Skip to content

Commit 37d0549

Browse files
committed
Squashed commit from mcp/agentops-api changes
0 parents  commit 37d0549

File tree

10 files changed

+1122
-0
lines changed

10 files changed

+1122
-0
lines changed

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Use a Python image with uv pre-installed
2+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS uv
3+
4+
# Install the project into `/app`
5+
WORKDIR /app
6+
7+
# Enable bytecode compilation
8+
ENV UV_COMPILE_BYTECODE=1
9+
10+
# Copy from the cache instead of linking since it's a mounted volume
11+
ENV UV_LINK_MODE=copy
12+
13+
# Install the project's dependencies using the lockfile and settings
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
--mount=type=bind,source=uv.lock,target=uv.lock \
16+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17+
uv sync --frozen --no-install-project --no-dev --no-editable
18+
19+
# Then, add the rest of the project source code and install it
20+
# Installing separately from its dependencies allows optimal layer caching
21+
ADD . /app
22+
RUN --mount=type=cache,target=/root/.cache/uv \
23+
uv sync --frozen --no-dev --no-editable
24+
25+
FROM python:3.12-slim-bookworm
26+
27+
WORKDIR /app
28+
29+
COPY --from=uv /root/.local /root/.local
30+
COPY --from=uv --chown=app:app /app/.venv /app/.venv
31+
32+
# Place executables in the environment at the front of the path
33+
ENV PATH="/app/.venv/bin:$PATH"
34+
35+
# Use default API URL (https://api.agentops.ai) - agents can override per-request
36+
ENTRYPOINT ["python", "-m", "mcp_server_agentops_api"]

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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

bin/run-server

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# Get the absolute path to the script directory
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
5+
6+
# Go to the parent directory (project root)
7+
cd "$SCRIPT_DIR/.."
8+
9+
# Run the MCP server
10+
uv run -m mcp_server_agentops_api "$@"

pyproject.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[project]
2+
name = "mcp-server-agentops-api"
3+
version = "0.1.0"
4+
description = "A Model Context Protocol server for the AgentOps API"
5+
readme = "README.md"
6+
requires-python = ">= 3.10"
7+
authors = [{ name = "AgentOps" }]
8+
keywords = ["agentops", "analytics", "mcp", "llm", "monitoring"]
9+
license = { text = "MIT" }
10+
classifiers = [
11+
"Development Status :: 4 - Beta",
12+
"Intended Audience :: Developers",
13+
"License :: OSI Approved :: MIT License",
14+
"Programming Language :: Python :: 3",
15+
"Programming Language :: Python :: 3.10",
16+
]
17+
dependencies = [
18+
"httpx >= 0.25.0",
19+
"mcp >= 1.1.3",
20+
"pydantic >= 2.0.0",
21+
]
22+
23+
[project.scripts]
24+
mcp-server-agentops-api = "mcp_server_agentops_api:main"
25+
26+
[build-system]
27+
requires = ["hatchling"]
28+
build-backend = "hatchling.build"
29+
30+
[tool.uv]
31+
dev-dependencies = ["pyright >= 1.1.389", "ruff >= 0.7.3"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from .server import serve
2+
3+
# Default API endpoint
4+
DEFAULT_API_URL = "https://api.agentops.ai"
5+
6+
def main():
7+
"""MCP AgentOps API Server - Integration with AgentOps API for MCP"""
8+
import argparse
9+
import asyncio
10+
11+
parser = argparse.ArgumentParser(
12+
description="Provide MCP tools for interacting with the AgentOps API"
13+
)
14+
parser.add_argument("--api-url", type=str, default=DEFAULT_API_URL,
15+
help=f"Base URL for AgentOps API (default: {DEFAULT_API_URL})")
16+
17+
args = parser.parse_args()
18+
19+
print(f"Starting AgentOps API MCP server with API URL: {args.api_url}")
20+
asyncio.run(serve(args.api_url))
21+
22+
23+
if __name__ == "__main__":
24+
main()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# __main__.py
2+
3+
from mcp_server_agentops_api import main
4+
5+
main()

0 commit comments

Comments
 (0)