|
| 1 | +# AgentOps API MCP Server |
| 2 | + |
| 3 | +An MCP (Model Coordination Protocol) server that allows LLM agents to interact with the AgentOps API for accessing trace data. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This MCP server provides tools for agents to: |
| 8 | + |
| 9 | +- List recent traces from their AgentOps project |
| 10 | +- Get detailed information about specific traces |
| 11 | + |
| 12 | +The server handles authentication and communication with the AgentOps API, making it easy for agents to access their trace data. |
| 13 | + |
| 14 | +## Authentication Flow |
| 15 | + |
| 16 | +The server uses a secure two-step authentication process: |
| 17 | + |
| 18 | +1. The agent provides their AgentOps API key with each request |
| 19 | +2. The server exchanges this API key for a JWT token from the AgentOps API |
| 20 | +3. The server uses this JWT token to make authenticated requests to the AgentOps API |
| 21 | +4. All responses are passed back to the agent in their raw form |
| 22 | + |
| 23 | +This ensures that API keys are never stored between requests, and each request is authenticated securely with a JWT token. |
| 24 | + |
| 25 | +## Available Tools |
| 26 | + |
| 27 | +### `list_traces` |
| 28 | + |
| 29 | +Lists the most recent traces from the agent's project. |
| 30 | + |
| 31 | +**Parameters:** |
| 32 | +- `AGENTOPS_API_KEY` (required): The agent's AgentOps API key |
| 33 | +- `limit` (optional): Maximum number of traces to return (default: 5) |
| 34 | +- `AGENTOPS_API_URL` (optional): Custom API URL for non-production environments |
| 35 | + |
| 36 | +**Response:** |
| 37 | +- List of traces with trace ID, number of spans, start/end time |
| 38 | +- Total number of traces in the database |
| 39 | +- Traces sorted by creation timestamp (most recent first) |
| 40 | + |
| 41 | +### `trace_detail` |
| 42 | + |
| 43 | +Gets detailed information about a specific trace. |
| 44 | + |
| 45 | +**Parameters:** |
| 46 | +- `AGENTOPS_API_KEY` (required): The agent's AgentOps API key |
| 47 | +- `trace_id` (required): The trace ID to retrieve details for (from the `trace_id` field in `list_traces` response) |
| 48 | +- `AGENTOPS_API_URL` (optional): Custom API URL for non-production environments |
| 49 | + |
| 50 | +**Response:** |
| 51 | +- Detailed information about the trace |
| 52 | +- All spans associated with the trace |
| 53 | +- Metadata, timing information, etc. |
| 54 | + |
| 55 | +## Usage |
| 56 | + |
| 57 | +### Using with Claude Coder (Recommended) |
| 58 | + |
| 59 | +This MCP server is designed to work with Claude Coder. Follow these steps to set it up: |
| 60 | + |
| 61 | +1. **Configure Claude Coder** |
| 62 | + |
| 63 | + Add this to your Claude Coder configuration file (typically `~/.config/claude-cli/config.yaml`): |
| 64 | + |
| 65 | + ```yaml |
| 66 | + mcp_servers: |
| 67 | + - name: agentops-api |
| 68 | + path: /ABSOLUTE/PATH/TO/mcp/agentops-api/bin/run-server |
| 69 | + description: "AgentOps API integration for accessing trace data" |
| 70 | + ``` |
| 71 | +
|
| 72 | + Replace `/ABSOLUTE/PATH/TO` with the actual path to this repository. |
| 73 | + |
| 74 | +2. **Use with Claude Coder** |
| 75 | + |
| 76 | + ```bash |
| 77 | + # Run Claude with the AgentOps API MCP server enabled |
| 78 | + claude --mcp agentops-api |
| 79 | + |
| 80 | + # Or for a single command |
| 81 | + claude --mcp agentops-api "List my recent traces. My API key is xyz123" |
| 82 | + ``` |
| 83 | + |
| 84 | +3. **In your prompts to Claude, include your AgentOps API key:** |
| 85 | + |
| 86 | + ``` |
| 87 | + Can you show me my recent traces? Find my agentops api key in my user .env file. |
| 88 | + ``` |
| 89 | +
|
| 90 | +### Running Standalone |
| 91 | +
|
| 92 | +If you need to run the server directly: |
| 93 | +
|
| 94 | +```bash |
| 95 | +# Using the convenience script |
| 96 | +./bin/run-server |
| 97 | +
|
| 98 | +# Or using Python directly |
| 99 | +uv run -m mcp_server_agentops_api |
| 100 | +``` |
| 101 | + |
| 102 | +The server uses the production AgentOps API at `https://api.agentops.ai` by default. Agents can override this URL on a per-request basis. |
| 103 | + |
| 104 | +### Available Tool Calls |
| 105 | + |
| 106 | +When using the MCP server through Claude, these are the tools it can use: |
| 107 | + |
| 108 | +``` |
| 109 | +# List recent traces |
| 110 | +list_traces(AGENTOPS_API_KEY="your-api-key", limit=10) |
| 111 | +
|
| 112 | +# Get details for a specific trace |
| 113 | +trace_detail(AGENTOPS_API_KEY="your-api-key", trace_id="148dac266d95c9dc0b5616320b8488c9") |
| 114 | +
|
| 115 | +# Using a custom API URL (e.g., for local development) |
| 116 | +list_traces(AGENTOPS_API_KEY="your-api-key", AGENTOPS_API_URL="http://localhost:8000") |
| 117 | +``` |
| 118 | + |
| 119 | +## Architecture |
| 120 | + |
| 121 | +The code is organized into three main components: |
| 122 | + |
| 123 | +1. **Client (`client.py`)**: Handles communication with the AgentOps API, including authentication |
| 124 | +2. **Tools (`tools.py`)**: Defines the tools available to agents and processes tool requests |
| 125 | +3. **Server (`server.py`)**: Implements the MCP server that agents interact with |
| 126 | + |
| 127 | +Each request is stateless, with no user data stored between requests, and raw API responses are returned directly to the agent. |
| 128 | + |
| 129 | +## Docker |
| 130 | + |
| 131 | +```bash |
| 132 | +# Build and run the Docker container |
| 133 | +docker build -t mcp-server-agentops-api . |
| 134 | +docker run mcp-server-agentops-api |
| 135 | +``` |
| 136 | + |
| 137 | +## Future Enhancements |
| 138 | + |
| 139 | +- Additional AgentOps API tools (metrics, spans, etc.) |
| 140 | +- Support for filtering and searching traces |
| 141 | +- Batch operations for improved performance |
| 142 | +- Caching of JWT tokens for a short period |
0 commit comments