Work with MCP server
Use the MCP server when you need to implement or modify Model Context Protocol tool handlers for Attune AI workflows.
Prerequisites
- Access to the project source code
- Familiarity with the files under
src/attune/mcp/ - Understanding of MCP (Model Context Protocol) concepts
Steps
-
Identify the server component to modify
Determine which part of the MCP server handles your use case:
- Prompts: Use
src/attune/mcp/prompts.pyfor prompt templates - Tools: Use
src/attune/mcp/tool_schemas.pyfor tool definitions - Server core: Use
src/attune/mcp/server.pyfor server lifecycle - Memory handlers: Use
src/attune/mcp/memory_handlers.pyfor memory operations - Rate limiting: Use
src/attune/mcp/rate_limiter.pyfor call throttling
- Prompts: Use
-
Review the existing implementation
Open the relevant file and examine:
- The function signature and docstring
- Input parameters and return types
- Error handling patterns
- Integration with other components
-
Create your MCP server instance
If working with a new server instance:
from attune.mcp.server import create_server server = create_server() -
Modify the appropriate handler
Make your changes following the established patterns:
- Tool functions return
dict[str, Any]with structured responses - Use the rate limiter for external API calls
- Follow the naming convention for new tools
- Include proper error handling with meaningful messages
- Tool functions return
-
Test your changes
Run the MCP server tests to verify your implementation:
pytest -k "mcp" --verbose
Verify success
Your implementation is working when:
- The MCP server starts without errors using
main() - Your tool appears in the tool list from
get_tool_list() - Tool calls return the expected response format
- Rate limiting prevents excessive API usage
- All existing tests continue to pass