Skip to content

feat(adapters): FastMCP Catalog bridge — auto-ingest tools from FastMCP servers (#114)#177

Merged
dgenio merged 3 commits intomainfrom
feat/issue-114-fastmcp-catalog-bridge
Apr 15, 2026
Merged

feat(adapters): FastMCP Catalog bridge — auto-ingest tools from FastMCP servers (#114)#177
dgenio merged 3 commits intomainfrom
feat/issue-114-fastmcp-catalog-bridge

Conversation

@dgenio
Copy link
Copy Markdown
Owner

@dgenio dgenio commented Apr 15, 2026

Summary

Closes #114

Adds adapters/fastmcp.py — a bridge between FastMCP servers and contextweaver Catalog objects. Converts FastMCP tool definitions into SelectableItems with namespace inference, tag mapping, and schema preservation, and provides live server discovery via the FastMCP Client.

What changed

  • src/contextweaver/adapters/fastmcp.py (new) — core module with:
    • infer_fastmcp_namespace() — 2-segment namespace inference matching FastMCP's {namespace}_{name} composition convention (vs 3+ in the generic MCP adapter)
    • fastmcp_tool_to_selectable() — convert tool definition dicts to SelectableItem, delegating annotation/schema parsing to the existing mcp_tool_to_selectable(), then adjusting id, namespace, name, and tags
    • fastmcp_tools_to_catalog() — batch-convert to a populated Catalog
    • load_fastmcp_catalog() — async live discovery from any FastMCP source (server instance, URL, file path, config dict, existing Client) via tools/list
  • src/contextweaver/adapters/__init__.py — re-exports new public names
  • pyproject.toml — adds contextweaver[fastmcp] optional extra (fastmcp>=2.0)
  • tests/test_adapters.py — 22 new tests: namespace inference, tag mapping, schema preservation, annotations, catalog building, import guard
  • examples/fastmcp_adapter_demo.py (new) — standalone example showing namespace inference, tool conversion, catalog building, filtering, and hydration
  • CHANGELOG.md — entry under [Unreleased] / Added

Why

FastMCP powers ~70% of MCP servers. Without a direct bridge, users must manually convert each tool definition—this friction blocks adoption. The adapter reuses mcp_tool_to_selectable() internally and adds FastMCP-specific namespace inference and tag mapping on top.

How verified

ruff format src/ tests/ examples/   → 84 files left unchanged
ruff check src/ tests/ examples/    → All checks passed!
mypy src/                           → Success: no issues found in 42 source files
pytest -q tests/test_adapters.py    → 90 passed in 0.27s
pytest -q                           → 563 passed in 6.13s
python examples/fastmcp_adapter_demo.py → runs successfully
python -m contextweaver demo         → runs successfully
All 10 example scripts               → run successfully

Tradeoffs / risks

  • infer_fastmcp_namespace accepts 2-segment underscore names (e.g. github_search → ns=github), which is more aggressive than the generic MCP heuristic. This matches FastMCP composition conventions but may over-infer for non-FastMCP tools — users can pass namespace= to override.
  • load_fastmcp_catalog is async (matching the context/ async-first convention). Callers in sync contexts need asyncio.run().
  • Module is 271 lines (under the 300-line limit).

Checklist

  • Tests added/updated for every new/changed public function
  • make ci targets pass locally (fmt, lint, type, test, example, demo)
  • CHANGELOG.md updated under [Unreleased]
  • Google-style docstrings for all new public APIs
  • Module ≤ 300 lines (271 lines)
  • Related issue linked ([adapters] FastMCP Catalog bridge — auto-ingest tools from FastMCP servers #114)
  • No print() in library code
  • No business logic in __init__.py

…CP servers (#114)

Add adapters/fastmcp.py with utilities to bridge FastMCP servers and
contextweaver Catalogs:

- fastmcp_tool_to_selectable() — convert FastMCP tool definition dicts to
  SelectableItem, with 2-segment namespace inference matching FastMCP
  composition conventions and tag mapping from meta.tags
- fastmcp_tools_to_catalog() — batch-convert tool definitions into a
  populated Catalog with namespace-scoped filtering
- load_fastmcp_catalog() — async live discovery from any FastMCP source
  (FastMCP instance, URL, file path, config dict, Client) via tools/list
- infer_fastmcp_namespace() — FastMCP-aware namespace inference accepting
  2+ underscore-delimited segments (vs 3+ in generic MCP adapter)
- contextweaver[fastmcp] optional extra (fastmcp>=2.0)
- Example recipe in examples/fastmcp_adapter_demo.py
- 22 new tests covering namespace inference, tag mapping, schema
  preservation, annotations, catalog building, and import guard
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a FastMCP-to-Catalog adapter so FastMCP servers (and their tools/list outputs) can be converted into contextweaver SelectableItems and loaded into a Catalog, with an optional extra for live discovery via fastmcp.Client.

Changes:

  • Introduces src/contextweaver/adapters/fastmcp.py with namespace inference, tool conversion, catalog building, and async live discovery.
  • Exposes the new adapter functions via src/contextweaver/adapters/__init__.py and adds a fastmcp optional extra in pyproject.toml.
  • Adds FastMCP-focused tests and an example demo script, plus a CHANGELOG entry.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/contextweaver/adapters/fastmcp.py New FastMCP adapter (namespace inference, conversion, catalog creation, async discovery).
src/contextweaver/adapters/__init__.py Re-exports FastMCP adapter public API.
pyproject.toml Adds contextweaver[fastmcp] optional dependency group.
tests/test_adapters.py Adds tests for FastMCP namespace inference, conversion, catalog building, and import guard.
examples/fastmcp_adapter_demo.py Adds a standalone demo for dict-based conversion and catalog usage.
CHANGELOG.md Documents the new adapter under [Unreleased].

Comment thread src/contextweaver/adapters/fastmcp.py Outdated
Comment thread src/contextweaver/adapters/fastmcp.py
Comment thread src/contextweaver/adapters/__init__.py
Comment thread src/contextweaver/adapters/fastmcp.py
@dgenio dgenio merged commit ae8cc00 into main Apr 15, 2026
3 checks passed
@dgenio dgenio deleted the feat/issue-114-fastmcp-catalog-bridge branch April 15, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[adapters] FastMCP Catalog bridge — auto-ingest tools from FastMCP servers

2 participants