Skip to main content

MCP Wrapper for AgentSociety

A library that wraps low-level MCP client functionality, exposing it for easy usage as tools within a LangChain workflow. This enables seamless integration of remote MCP tools for language model workflows and agent applications.

Structure

Library Code: mcpwrap/

  • client.py — Basic utility to invoke a LangChain model with a set of tools.
  • server_stub.py — Async abstraction (ServerSession) for connecting to and interfacing with an MCP server, exposing MCP tools for LangChain.
  • multi_mcp_model.py — Orchestrates multiple MCP server sessions and integrates their toolsets for use by one BaseChatModel. Handles async invocation and batching of tool requests.
  • llm_integration.py — Converts MCP tool schemas (JSON Schema) into dynamic, structured LangChain tools using Pydantic models.
  • (You may need to install mcp and LangChain dependencies.)

Example App: sample/

  • Provides a minimal, integration-tested example of how to use this library in practice. (See directory for details.)

Usage Overview

1. Connect MCP servers as tool providers

from mcpwrap.server_stub import ServerSession

session = ServerSession(name="example", url="http://localhost:8080")
await session.initialize()  # Async context

2. Compose Multi-server Tools for LangChain

from langchain_core.language_models.chat_models import BaseChatModel
from mcpwrap.multi_mcp_model import MultiMcpModel

base_model = ... # Any supported BaseChatModel
mcp_model = MultiMcpModel(
    base_model=base_model,
    mcp_servers=[session]  # Add as many as you like
)
await mcp_model.initialize()

3. Use in a Chat Workflow

results = await mcp_model.ainvoke(messages)  # messages: List[BaseMessage]

Features

  • Wraps multiple MCP servers: Maps their tools to a common namespace for use as LangChain tools.
  • Schema Conversion: Converts arbitrary MCP tool JSON schemas into Pydantic models for argument validation.
  • Async, batched operations: Tools are called concurrently when invoked by an LLM agent.
  • Error and retry handling: Optionally retries failed server/tool executions.

Requirements

  • pip install -r requirements.txt

Notes

  • Ensure MCP servers are reachable at their configured URLs.
  • Schema support currently assumes JSON Schema Draft 7 compatibility for tool arguments.

Contributing

PRs, issues, and questions are welcome!

Metadata

Release files for agent-society-mcp-client-wrapper 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-society-mcp-client-wrapper 0.0.3
File Size Uploaded Provenance
agent_society_mcp_client_wrapper-0.0.3.tar.gz 6.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-society-mcp-client-wrapper 0.0.3
File Interpreter ABI Platform
agent_society_mcp_client_wrapper-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 13.8 kB

Release files / agent_society_mcp_client_wrapper-0.0.3.tar.gz

Download URL agent_society_mcp_client_wrapper-0.0.3.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5762186744b21c38d422eeb63a50f48f12c4b747faa078d24ad73cadb23da79b
BLAKE2b-256 checksum
How to use checksums
75365967029068f78315e396f87bb5ba497bba965360b132b3d14ff96bb01f8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / agent_society_mcp_client_wrapper-0.0.3-py3-none-any.whl

Download URL agent_society_mcp_client_wrapper-0.0.3-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b73de219af486af7ca3b8d31f8339d2f86c921a158e3123b06280ac07ee0f56b
BLAKE2b-256 checksum
How to use checksums
f284529efd36ece111f9f73360ca15c39e083b65b9d6cec0179bdc466f275370
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for agent-society-mcp-client-wrapper 0.0.3

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page