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

Steps

  1. Identify the server component to modify

    Determine which part of the MCP server handles your use case:

    • Prompts: Use src/attune/mcp/prompts.py for prompt templates
    • Tools: Use src/attune/mcp/tool_schemas.py for tool definitions
    • Server core: Use src/attune/mcp/server.py for server lifecycle
    • Memory handlers: Use src/attune/mcp/memory_handlers.py for memory operations
    • Rate limiting: Use src/attune/mcp/rate_limiter.py for call throttling
  2. 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
  3. Create your MCP server instance

    If working with a new server instance:

    from attune.mcp.server import create_server
    server = create_server()
    
  4. 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
  5. Test your changes

    Run the MCP server tests to verify your implementation:

    pytest -k "mcp" --verbose
    

Verify success

Your implementation is working when: