autogentmcp_server

autogentmcp/autogentmcp_server

3.2

If you are the rightful owner of autogentmcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The MCP Registry Server is a FastAPI-based server designed to dynamically fetch agent/tool metadata from a registry and utilize LangGraph with Ollama for intelligent tool selection and orchestration.

MCP Registry Server

A FastAPI-based Model Context Protocol (MCP) server that dynamically fetches agent/tool metadata from a registry and uses LangGraph with Ollama for intelligent tool selection and orchestration.

Features

  • Dynamic Agent/Tool Loading: Fetches metadata from external registry
  • LLM-driven Tool Selection: Uses Ollama to select the best agent and tool for each query
  • Modular Architecture: Clean separation of concerns with dedicated modules
  • Authentication Support: Handles multiple authentication types (API Key, Bearer, Basic, OAuth2)
  • Session Management: Maintains conversation context across multiple turns
  • Diagram Support: Renders Mermaid and PlantUML diagrams in responses
  • Background Registry Sync: Automatically refreshes agent metadata every 5 minutes

Architecture

The server is built with a modular architecture:

app/
ā”œā”€ā”€ main.py                 # FastAPI application entry point
ā”œā”€ā”€ langgraph_router.py     # Main orchestration logic
ā”œā”€ā”€ auth_handler.py         # Authentication management
ā”œā”€ā”€ llm_client.py           # LLM interaction wrapper
ā”œā”€ā”€ session_manager.py      # Session context management
ā”œā”€ā”€ tool_selector.py        # Agent and tool selection
ā”œā”€ā”€ endpoint_invoker.py     # HTTP endpoint invocation
ā”œā”€ā”€ registry.py             # Registry sync and caching
└── agents.py               # Agent/tool data structures

Authentication

The server supports multiple authentication methods:

Supported Types

  1. API Key (apiKey)

    • Header-based: X-API-Key: your-key
    • Query parameter: ?api_key=your-key
    • Custom format: Authorization: Bearer {key}
  2. Bearer Token (bearer)

    • Authorization: Bearer your-token
  3. Basic Auth (basic)

    • Authorization: Basic base64(username:password)
  4. OAuth2 (oauth2)

    • Authorization: Bearer access-token

Configuration

Authentication is configured through registry metadata:

{
  "security": {
    "type": "apiKey",
    "location": "header",
    "header_name": "X-API-Key",
    "format": "direct"
  }
}

Credential Management

Environment Variables
export MCP_DEFAULT_API_KEY="your-default-key"
export MCP_DEFAULT_BEARER_TOKEN="your-default-token"
export MCP_DEFAULT_BASIC_USER="username"
export MCP_DEFAULT_BASIC_PASS="password"
Configuration File

Copy auth_config.json.example to auth_config.json and update:

{
  "credentials": {
    "jsonplaceholder_api_key": "your-api-key-here",
    "github_api_key": "your-github-token-here"
  },
  "agent_specific": {
    "JSONPlaceholder": {
      "api_key": "specific-key-for-jsonplaceholder"
    }
  }
}
Runtime API
# Set credentials via API
curl -X POST "http://localhost:8000/auth/set_credential" \
  -H "Content-Type: application/json" \
  -d '{"key": "github_api_key", "value": "github_pat_xxxxx"}'

Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. Start Ollama server:
ollama serve
ollama pull qwen3:14b
  1. Configure authentication (optional):
cp auth_config.json.example auth_config.json
# Edit auth_config.json with your credentials
  1. Start the server:
uvicorn app.main:app --reload

Usage

Query Endpoint

curl -X POST "http://localhost:8000/query" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Get user with ID 123",
    "session_id": "user-session-1"
  }'

Session Management

# Get all sessions
curl "http://localhost:8000/sessions"

# Get specific session
curl "http://localhost:8000/sessions/user-session-1"

# Clear session
curl -X DELETE "http://localhost:8000/sessions/user-session-1"

Registry Management

# Manually sync registry
curl -X POST "http://localhost:8000/sync_registry"

API Endpoints

  • GET /health - Health check
  • POST /query - Process user query
  • POST /sync_registry - Manually sync registry
  • POST /auth/set_credential - Set authentication credential
  • GET /sessions - List all sessions
  • GET /sessions/{session_id} - Get session details
  • DELETE /sessions/{session_id} - Clear session

Registry Format

The server expects registry data in this format:

{
  "agents": {
    "JSONPlaceholder": {
      "description": "JSONPlaceholder API for testing",
      "base_domain": "https://jsonplaceholder.typicode.com",
      "security": {
        "type": "apiKey",
        "location": "header",
        "header_name": "X-API-Key"
      },
      "tools": [
        {
          "name": "get_user",
          "description": "Get user by ID",
          "endpoint_uri": "/users/{id}",
          "method": "GET"
        }
      ]
    }
  }
}

Development

Running Tests

pytest tests/

Code Style

black app/
flake8 app/

Building

docker build -t mcp-registry-server .

Configuration

Environment Variables

  • MCP_DEFAULT_API_KEY - Default API key
  • MCP_DEFAULT_BEARER_TOKEN - Default bearer token
  • MCP_DEFAULT_BASIC_USER - Default basic auth username
  • MCP_DEFAULT_BASIC_PASS - Default basic auth password
  • OLLAMA_BASE_URL - Ollama server URL (default: http://localhost:11434)
  • OLLAMA_MODEL - Ollama model name (default: qwen3:14b)

Registry Configuration

The registry URL is configured in app/registry.py. Update the REGISTRY_URL constant to point to your registry endpoint.

Troubleshooting

Common Issues

  1. LLM not responding: Check Ollama server is running and model is available
  2. Authentication failures: Verify credentials in auth_config.json or environment variables
  3. Registry sync errors: Check network connectivity and registry URL
  4. JSON parsing errors: Enable debug logging to see LLM responses

Debug Logging

The server includes extensive logging. Look for log messages prefixed with:

  • [AuthHandler] - Authentication issues
  • [LLMClient] - LLM interaction problems
  • [SessionManager] - Session management
  • [ToolSelector] - Agent/tool selection
  • [EndpointInvoker] - HTTP request issues

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

MIT License