Appearance
MCP Tools
The Model Context Protocol (MCP) is an open standard for connecting AI models to external tools and data sources. Elsai has first-class MCP support — connect any MCP server in seconds.
What is MCP?
MCP servers expose tools, resources, and prompts over a standardised protocol. Thousands of pre-built MCP servers exist for databases, APIs, file systems, browsers, and more.
Basic usage
python
from elsai import Agent
from elsai.tools.mcp import MCPClient
from mcp import stdio_client, StdioServerParameters
# Connect to an MCP server via stdio
client = MCPClient(
lambda: stdio_client(StdioServerParameters(
command="uvx",
args=["mcp-server-fetch"]
))
)
with client:
tools = client.list_tools_sync()
agent = Agent(tools=tools)
result = agent("Fetch the content of https://example.com")
print(result)Async context manager
python
import asyncio
from elsai import Agent
from elsai.tools.mcp import MCPClient
from mcp import stdio_client, StdioServerParameters
async def main():
client = MCPClient(
lambda: stdio_client(StdioServerParameters(
command="uvx",
args=["mcp-server-filesystem", "/tmp"]
))
)
async with client:
tools = await client.list_tools()
agent = Agent(tools=tools)
result = await agent.invoke_async("List all files in the /tmp directory")
print(result)
asyncio.run(main())HTTP/SSE transport
Connect to an MCP server running as an HTTP service:
python
from elsai.tools.mcp import MCPClient
from mcp.client.sse import sse_client
client = MCPClient(
lambda: sse_client("http://localhost:8080/sse")
)
with client:
agent = Agent(tools=client.list_tools_sync())
agent("Use the remote server tools")AWS Documentation MCP server
python
from elsai import Agent
from elsai.tools.mcp import MCPClient
from mcp import stdio_client, StdioServerParameters
aws_docs = MCPClient(
lambda: stdio_client(StdioServerParameters(
command="uvx",
args=["awslabs.aws-documentation-mcp-server@latest"]
))
)
with aws_docs:
agent = Agent(tools=aws_docs.list_tools_sync())
result = agent("How do I use Amazon Bedrock with Python?")Combining MCP tools with function tools
python
from elsai import Agent, tool
from elsai.tools.mcp import MCPClient
from mcp import stdio_client, StdioServerParameters
@tool
def my_custom_tool(x: str) -> str:
"""A custom Python tool.
Args:
x: Input value.
"""
return x.upper()
client = MCPClient(
lambda: stdio_client(StdioServerParameters(command="uvx", args=["mcp-server-fetch"]))
)
with client:
agent = Agent(tools=[my_custom_tool, *client.list_tools_sync()])
agent("Use both custom and MCP tools")Filtering MCP tools
Only expose a subset of an MCP server's tools:
python
all_tools = client.list_tools_sync()
filtered = [t for t in all_tools if t.name in {"read_file", "write_file"}]
agent = Agent(tools=filtered)Multiple MCP servers
python
from elsai.tools.mcp import MCPClient
from mcp import stdio_client, StdioServerParameters
db_client = MCPClient(lambda: stdio_client(StdioServerParameters(command="uvx", args=["mcp-server-postgres", "--url", DATABASE_URL])))
fs_client = MCPClient(lambda: stdio_client(StdioServerParameters(command="uvx", args=["mcp-server-filesystem", "."])))
with db_client, fs_client:
tools = [*db_client.list_tools_sync(), *fs_client.list_tools_sync()]
agent = Agent(tools=tools)
agent("Read the schema from the database and write it to a file")MCP resources
Access MCP resources (not just tools):
python
async with client:
resources = await client.list_resources()
for resource in resources:
print(f"{resource.name}: {resource.uri}")
content = await client.read_resource("file:///path/to/file.txt")Popular MCP servers
| Package | What it does |
|---|---|
mcp-server-fetch | Fetch web pages |
mcp-server-filesystem | Read/write local files |
mcp-server-postgres | Query PostgreSQL |
mcp-server-sqlite | Query SQLite |
mcp-server-github | GitHub API |
awslabs.aws-documentation-mcp-server | AWS docs |
mcp-server-brave-search | Brave web search |
Install any MCP server with uvx <package> (no installation needed) or pip install <package>.