Skip to main content
AG-Kit provides comprehensive support for the Model Context Protocol (MCP), enabling seamless integration with external tools and services while exposing AG-Kit tools to other MCP-compatible applications.

AG-Kit MCP Support

Client Implementation

Connect to existing MCP servers and use their tools:
from ag_kit_py.tools.mcp import MCPToolkit
from ag_kit_py.agents import LangGraphAgent
from langgraph.graph import StateGraph, MessagesState

# Create MCP toolkit
toolkit = MCPToolkit('mcp-toolkit')
await toolkit.add_server('filesystem', {
    'name': 'filesystem-server',
    'version': '1.0.0',
    'transport': {
        'type': 'stdio',
        'command': 'npx',
        'args': ['@modelcontextprotocol/server-filesystem', './workspace']
    }
})

# Initialize toolkit to load tools
await toolkit.initialize()

# Get available tools
tools = toolkit.get_tools()

# Note: MCP tools integration with LangGraph would be implemented
# in the specific workflow nodes, similar to the examples in:
# python-sdk/examples/langgraph/agents/agentic_chat/agent.py

Server Implementation

Expose AG-Kit tools as MCP servers:
from ag_kit_py.tools.mcp import AGKitMCPServer
from ag_kit_py.tools import tool
from pydantic import BaseModel

class WeatherInput(BaseModel):
    city: str

async def weather_func(input_data: WeatherInput, context=None):
    return {
        'city': input_data.city,
        'temperature': 22,
        'condition': 'sunny'
    }

weather_tool = tool(
    func=weather_func,
    name='get_weather',
    description='Get weather information',
    schema=WeatherInput
)

server = AGKitMCPServer({
    'name': 'weather-service',
    'version': '1.0.0'
})

server.register_tool(weather_tool)
await server.run({'type': 'stdio'})

Connection Types

  • Stdio: Local command-line tools
  • HTTP: Remote web services
  • Memory: Testing and in-process communication

Key Features

  • Tool Discovery: Automatic tool registration and discovery
  • Type Safety: Strongly typed tool definitions
  • Multiple Transports: Support for stdio, HTTP, and memory connections
  • Error Handling: Built-in error handling and recovery

Next Steps