swarmauri_toolkit_mcpclient
swarmauri_toolkit_mcpclient
Discover and call Model Context Protocol server tools from Swarmauri agents.
Overview · Installation · Quick Start · Usage · API · Contributing · Governance · License
Overview
Summary
Connect Swarmauri agents to tools exposed by a Model Context Protocol (MCP) server.
Why This Package
The adapter turns advertised MCP tools into Swarmauri tool objects and reuses one client session across discovery and invocation.
When to Use
Use this toolkit when your agent needs tools provided by a local subprocess or a remote MCP endpoint.
Features
- Discover every page of server tools and restrict exposure with an optional allowlist.
- Connect over stdio or Streamable HTTP.
- Call tools synchronously or through the asynchronous wrapper.
- Return MCP content blocks, structured output and the tool error flag.
Non-Goals
The scope is client-side tool discovery and invocation. MCP resources, prompts, and server hosting are outside this package's scope.
Getting Started
Prerequisites
Use Python 3.10 through 3.14 and a running HTTP MCP server or a local command that launches a stdio server. The agent example also uses the Swarmauri standard kernel, which requires Python 3.11 or later.
Installation
Install with uv
swarmauri_toolkit_mcpclient is not declared published. From the source checkout:
uv pip install .
Install with pip
swarmauri_toolkit_mcpclient is not declared published. From the source checkout:
python -m pip install .
Install with Poetry
swarmauri_toolkit_mcpclient is not declared published. From a separate Poetry project, replace the path with your checkout:
poetry add /path/to/swarmauri_toolkit_mcpclient
Quick Start
Example
Source: docs/readme/quick_start.py.
"""Discover and call a tool on the example stdio MCP server."""
from pathlib import Path
import sys
from mcp import StdioServerParameters
from swarmauri_toolkit_mcpclient import MCPToolkit
if __name__ == "__main__":
fixture = (
Path(__file__).resolve().parents[2] / "tests/i9n/fixture_server.py"
)
server = StdioServerParameters(command=sys.executable, args=[str(fixture)])
with MCPToolkit.connect(server, allowed_tools={"sum_values"}) as toolkit:
result = toolkit.get_tool_by_name("sum_values")(values=[2, 3])
print(result["structuredContent"])
Expected Result
The stdio example prints a structured result containing {'total': 5}.
Usage
Common Workflows
Source: docs/readme/usage.py.
"""Give a Swarmauri agent access to a remote weather tool."""
from swarmauri_standard.agents.ToolAgent import ToolAgent
from swarmauri_toolkit_mcpclient import MCPToolkit
def ask_weather(llm, conversation):
"""Use a configured tool model and conversation to ask for the weather."""
with MCPToolkit.connect(
"https://weather.example.com/mcp",
allowed_tools={"get_weather"},
) as toolkit:
agent = ToolAgent(llm=llm, conversation=conversation, toolkit=toolkit)
return agent.exec(
"What's the weather in Chicago?",
llm_kwargs={"tool_choice": "auto"},
)
Configuration
Pass HTTP request headers with headers, configure the per-request timeout with timeout, and choose tools by original server name with allowed_tools.
OAuth for Streamable HTTP
Pass an MCP SDK OAuth provider as auth when opening the toolkit.
The provider authenticates both discovery and tool requests. Choose the provider
and token storage in the application before giving the toolkit to an agent.
from mcp.client.auth.extensions.client_credentials import (
ClientCredentialsOAuthProvider,
)
from swarmauri_toolkit_mcpclient import MCPToolkit
def connect_agent(endpoint, issuer, client_id, client_secret, storage):
"""Open an MCP session for a provisioned agent service principal."""
auth = ClientCredentialsOAuthProvider(
server_url=endpoint,
issuer=issuer,
client_id=client_id,
client_secret=client_secret,
storage=storage,
)
return MCPToolkit.connect(endpoint, auth=auth)
Use a separate service principal per autonomous agent when the MCP server must
authorize or audit them individually. Load each principal's credentials from the
application's secret store and pass its trusted authorization server issuer.
The SDK obtains a new access token when the current service token expires.
For user consent, pass mcp.client.auth.OAuthClientProvider with the application's
redirect and callback handlers. Set timeout to accommodate the consent window,
for example 300 seconds. The SDK uses authorization code with PKCE and renews
access during the connection when the issuer provides a refresh token. A delegated grant carries the user's permissions. A distinct
server-visible agent identity requires the issuer and server to support it.
Supply a separate SDK TokenStorage scope per agent, authorization issuer, MCP
resource, and delegated user or grant. The application controls persistence and
should coordinate concurrent connections that share a refresh-token grant. Use a
fresh provider per connection and HTTPS in production. A stored client
registration should be bound to its issuer. Keep credentials in the application
and turn consent or reauthorization into an application interaction.
Error Handling
Check isError in the result for server-reported tool failures. Transport and protocol failures raise exceptions. An unknown allowlist entry fails discovery.
Best Practices
Keep the connection context open for the entire agent run. Open a new context to rediscover the server's tool catalog.
Package Boundary
What It Owns
The toolkit owns the MCP client session, paginated tool discovery, name mapping, and submission of tool arguments and results.
Public API and Import Surfaces
Import MCPToolkit or MCPTool from swarmauri_toolkit_mcpclient. The installed toolkit is also available under swarmauri.toolkits.MCPToolkit.
Entry Points
swarmauri.toolkits→MCPToolkit→swarmauri_toolkit_mcpclient:MCPToolkit
Injected Dependencies
Provide a Streamable HTTP URL or an MCP StdioServerParameters object. Supply HTTP authentication headers when required by the endpoint.
Protocol Consumers
A Swarmauri ToolAgent consumes the toolkit through the existing toolkit and tool contracts. Direct callers can use get_tool_by_name.
Extensions
The OpenAI and Anthropic converters can read each tool's original JSON Schema. Other converters use the Swarmauri parameter metadata.
Operations and Readiness
Operational Requirements
The stdio transport requires permission to launch the configured executable. Streamable HTTP requires network access to the configured endpoint.
Health and Observability
Connection initialization and the first tool listing are completed before the context yields. Callers can record MCP tool outcomes and transport errors in their own logs.
Security and Resource Limits
Use an allowlist to limit the tools agents can invoke, and configure a request timeout appropriate for the server.
Compatibility
The toolkit uses MCP Python SDK 1.x and supports Python 3.10 through 3.14. Use await tool.acall(...) for direct calls from an asyncio application.
Verification
Tests
The package suite covers pagination, both transports, and an agent round trip with a mocked model response.
Certification Status
Package verification is covered by repository CI and local integration tests.
Evidence
See the MCP integration tests for the expected tool call, result, and error behavior.
FAQ
Why
A single toolkit lets an agent share the same MCP connection across tool calls.
How
Call MCPToolkit.connect and pass the toolkit to the agent or call a tool by its discovered name.
When
Connect before the agent starts. Exit the context when the agent finishes using server tools.
Documentation and Related Packages
More Documentation
See the MCP Python SDK for server and transport configuration.
Related Packages
swarmauri_base provides the toolkit and tool contracts. swarmauri_standard provides ToolAgent and the schema converters.
Project Links
Contributing
How to Contribute
Submit toolkit changes through the Swarmauri contribution guide.
Development Setup
From the repository root, run uv run --directory pkgs --package swarmauri_toolkit_mcpclient pytest 50-community/swarmauri_toolkit_mcpclient/tests.
Notes for Maintainers
Use the local MCP test fixture to validate changes to discovery or result translation without external model credentials.
Governance
Ownership and Decision Making
The Swarmauri SDK maintainers review changes to this community integration.
Standards and Policies
This README follows the repository's package README policy.
Lifecycle and Migration
This initial community package is available from a repository checkout. Reconnect to rebuild callable tools from server metadata.
License and Attribution
License
Licensed under Apache-2.0. See LICENSE.
Notices
See NOTICE for attribution.
Metadata
Release files for swarmauri_toolkit_mcpclient 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmauri_toolkit_mcpclient-0.1.0.tar.gz | 16.5 kB | Without provenance | Details for swarmauri_toolkit_mcpclient-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmauri_toolkit_mcpclient-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for swarmauri_toolkit_mcpclient-0.1.0-py3-none-any.whl |
Total release size: 31.0 kB
Release files / swarmauri_toolkit_mcpclient-0.1.0.tar.gz
| Download URL | swarmauri_toolkit_mcpclient-0.1.0.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10eacab02c367d326f4f5821e25a51996d148bf962b45b8384dbb0744daf967a
|
|
BLAKE2b-256 checksum How to use checksums |
2fea296432033d161ffe935188e6b64284c5f88f41bbbcdfb27f2ca7166ba8ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.13 {"installer":{"name":"uv","version":"0.13.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swarmauri_toolkit_mcpclient-0.1.0-py3-none-any.whl
| Download URL | swarmauri_toolkit_mcpclient-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
694a10a3c553c4686ff7215aea0ec9a05f70c9fff5bcb37236363b63749f6154
|
|
BLAKE2b-256 checksum How to use checksums |
d01563216073168b8666eced54b5382a7c81d8b0ed4aae26e19194326197dabc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.13 {"installer":{"name":"uv","version":"0.13.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for swarmauri_toolkit_mcpclient 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.