Skip to content

feat: add MCP tool integration#1042

Merged
ajbozarth merged 2 commits into
generative-computing:mainfrom
ajbozarth:feat/mcp-tools-core
May 11, 2026
Merged

feat: add MCP tool integration#1042
ajbozarth merged 2 commits into
generative-computing:mainfrom
ajbozarth:feat/mcp-tools-core

Conversation

@ajbozarth
Copy link
Copy Markdown
Contributor

@ajbozarth ajbozarth commented May 8, 2026

Tool PR

Description

Adds mellea/stdlib/tools/mcp.py, bridging MCP
server tools into Mellea's native tool-calling system. Any MCP server's tools
can now be discovered and used inside a Mellea agent.

Public API:

  • discover_mcp_tools(connection) -> list[MCPToolSpec]
  • MCPToolSpec.as_mellea_tool() -> MelleaTool
  • http_connection, sse_connection, stdio_connection transport helpers

Runtime: each tool invocation opens a short-lived MCP session and runs on
mellea's shared background event loop via _run_async_in_thread. Verified
end-to-end against the hosted GitHub MCP server.

Deps: mcp>=1.27.0 and httpx>=0.27 added to the mellea[tools] extra.
httpx is already transitive via smolagents and langchain-core.

Supersedes mellea-contribs#54,
which will be closed rather than merged. Jake suggested during review
that this belongs in core.

Issue #1032 point 2 (generalizing the async-to-sync wrapper onto
MelleaTool.from_callable) is handled by #1041.

Implementation Checklist

Protocol Compliance

  • Ensure compatibility with existing backends and providers
    • MCP tools are wrapped as standard MelleaTool instances via the constructor; no backend changes required.

Integration

  • Tool exported in mellea/stdlib/tools/__init__.py or, if you are adding a library of components, from your sub-module
    • Exported from the mellea.stdlib.tools.mcp submodule. Not added to __init__.py because the module imports mcp and httpx at top level and should only be loaded when the tools extra is installed.

Testing

  • Tests added to tests/stdlib/tools/
  • New code has 100% coverage
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Attribution

  • AI coding assistants used

Adds mellea/stdlib/tools/mcp.py, a new module that bridges MCP server
tools into Mellea's native tool-calling system. MCPToolSpec.as_mellea_tool()
wraps each discovered tool as a MelleaTool ready to pass via
ModelOption.TOOLS or to react().

Public API:
- discover_mcp_tools(connection) -> list[MCPToolSpec]
- MCPToolSpec.as_mellea_tool() -> MelleaTool
- http_connection, sse_connection, stdio_connection helpers

Each tool invocation opens a short-lived MCP session and runs on
mellea's shared background event loop via _run_async_in_thread, so
callers do not need to manage session lifetime. Verified end-to-end
against the hosted GitHub MCP server.

Adds mcp>=1.27.0 and httpx>=0.27 to the mellea[tools] extra. httpx
is already transitive via smolagents and langchain-core.

Assisted-by: Claude Code
Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
@ajbozarth
Copy link
Copy Markdown
Contributor Author

cc @akihikokuroda @psschwei @planetf1 @jakelorocco as reviewers from the original contribs PR

Copy link
Copy Markdown
Contributor

@planetf1 planetf1 left a comment

Choose a reason for hiding this comment

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

All the feedback from the contribs review is addressed — timeouts are now configurable with sensible defaults, all five content types are handled, and as_mellea_tool() is correctly typed. A few nits inline, nothing blocking.

Comment thread mellea/stdlib/tools/mcp.py Outdated
Comment thread mellea/stdlib/tools/mcp.py
Comment thread test/stdlib/tools/test_mcp.py Outdated
- Add return type annotation to `_open_session`.
- Log swallowed exceptions in the `ResourceLink` fallback path at debug
  level instead of discarding them silently.
- Drop redundant `_connection` private-attribute assertion in tests;
  wiring is already covered by the `_open_session` mocks used throughout.

Assisted-by: Claude Code
Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
@ajbozarth
Copy link
Copy Markdown
Contributor Author

@planetf1 addressed your nits, I'll hold off on merge for a bit to let anyone else re-review after the PR move from contribs to mellea. Otherwise I'll merge this as is at EOD

@ajbozarth ajbozarth added this pull request to the merge queue May 11, 2026
Merged via the queue into generative-computing:main with commit 6451a6d May 11, 2026
8 checks passed
@ajbozarth ajbozarth deleted the feat/mcp-tools-core branch May 11, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move MCP tool integration from contribs into core mellea

3 participants