MCP
A Model Context Protocol (MCP) wrapper for Agenite
The @agenite/mcp
package provides a client implementation for interacting with Model Context Protocol (MCP) servers. This enables Agenite agents to seamlessly access external data sources and capabilities through a standardized protocol.
What is MCP?
MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to large language models (LLMs). It creates a consistent way for LLMs to access data from various sources, similar to how USB-C provides a universal connection for hardware.
Key benefits of MCP include:
- Standardized integration: Connect to any MCP-compliant server using the same code
- Data security: Keep sensitive data within your infrastructure
- Flexibility: Switch between different data sources or LLM providers
- Extensibility: Use pre-built MCP servers or create your own
Installation
Basic usage
To use the MCP client with Agenite agents:
Connection types
The @agenite/mcp
package supports two transport mechanisms for connecting to MCP servers:
SSE transport
Server-sent events (SSE) transport allows connecting to remote MCP servers over HTTP:
Stdio transport
Standard I/O transport allows running MCP servers as local processes:
API reference
MCPClient
The main class for interacting with MCP servers.
Constructor
MCPServerConfig
There are two types of server configurations:
Methods
Tool integration
Tools returned by the MCPClient are standard @agenite/tool
instances that can be used directly with Agenite agents:
Common MCP servers
The MCP ecosystem includes several pre-built servers:
Server | Description | NPM Package |
---|---|---|
Fetch | Makes HTTP requests to fetch web content | @modelcontextprotocol/server-fetch |
Filesystem | Provides access to local files | @modelcontextprotocol/server-filesystem |
Sqlite | Connects to SQLite databases | @modelcontextprotocol/server-sqlite |
Weather | Fetches weather data | @modelcontextprotocol/server-weather |
Example: using multiple MCP servers
This example connects to both the fetch and filesystem MCP servers:
Understanding tool namespacing
When you get tools from multiple MCP servers, the MCPClient prefixes each tool name with the server name to avoid name collisions:
You can see the tool namespacing by inspecting the tools:
Advanced usage: getting tools by server
If you need to organize or filter tools by server:
Running your own MCP servers
You can run your own MCP servers for custom integrations:
For custom servers, see the MCP documentation on building servers.
MCP architecture
The MCP architecture follows a client-server model:
- MCPClient: Connects to one or more MCP servers
- MCP Servers: Provide tools that access specific data sources
- Tools: Exposed by servers and used by agents to perform actions
- Data Sources: Systems that provide data or functionality to the agent
Conclusion
The @agenite/mcp
package provides a powerful way to integrate external data sources and capabilities into your Agenite agents. By leveraging the standardized Model Context Protocol, you can create agents that interact with a wide range of systems without having to implement complex integrations for each one.
To explore more advanced MCP scenarios, check out the building a web research agent guide and the example code on GitHub.