Skip to content

Latest commit

 

History

History
134 lines (112 loc) · 6.82 KB

AGENTS.md

File metadata and controls

134 lines (112 loc) · 6.82 KB

opik-mcp

Installing the server to use it? Follow README.md; this file is for changing the code.

IMPORTANT: every token this server puts into a host's context has to pay for itself. Before adding output, a tool, a field or description text, say what it costs (bytes on the surface, tokens in a typical answer) and what the user gets for it. See ADR 0001.

  • The advertised surface has a hard byte budget.
  • Every read and list answer states its size.
  • The caller can always narrow: a span, a filter, a window, fields=[…].

What this is

An MCP server that lets an AI agent (Claude Code, Cursor, claude.ai) work with a user's Opik data: traces, spans, threads, projects, experiments, datasets, prompts and Diagnostics issues. The agent can answer "how is my project doing" or "what broke", and make small changes like scoring or closing a thread. It also authors the agent skills published as comet-ml/opik-skills.

How it ships: the opik-mcp package on PyPI (stdio, local API key), and a Docker image served at https://www.comet.com/opik/api/v1/mcp (Streamable HTTP, the user's OAuth token or API key passed through to the backend).

Stack: Python 3.13, uv, the official MCP python-sdk (FastMCP, pinned <2), httpx to the Opik REST API, Pydantic.

How a call flows:

  • read / list: server/tools/ → read_list/read_tool.py or list_tool.py → the entity's EntityHandler from read_list/registry.py → its module in read_list/entities/ → client/ → Opik backend.
  • write: writes/write_tool.py → writes/dispatch.py, which runs the operation from writes/registry.py through its hooks in writes/operations/ → client/ → backend. schema(operation) returns one operation's input on demand.
  • read_skill: serves the skills from skills_catalog.py. They are authored in plugins/opik/skills/ (the Claude Code plugin) and shipped in the wheel as opik_mcp/skills.
  • instructions.py renders the text a host receives on initialize. analytics/ sends product events; it is off in tests.

Commands

Command Proves Run by CI
make check lint + mypy + unit and conformance tests yes
make hermetic the real server process over stdio and HTTP, against a stub backend; not part of make check yes, own job
make slow the tests that spawn hooks, scripts, git, ruff and mypy; not part of make check yes
make skills-verify-source installing from this repo resolves exactly the authored skills yes
make plugin-validate claude plugin validate --strict passes on the marketplace and plugins/opik yes
make conformance the MCP wire contract only, for fast iteration inside check
make live the tools against a seeded real Opik; needs OPIK_URL yes, live.yaml
make user-flows real agent (OPIK-8491) not yet
make install-branch installs this worktree as MCP server opik-<ticket> no
make record-shapes regenerates read_list/record_shapes.json from opik's OpenAPI spec daily, record-shapes.yaml opens a PR

make runs mypy over src/, tests/ and the scripts, and ruff over everything, as CI does. Running them on src/ alone misses test and script errors.

Invariants (a red test here is a contract, not a flake)

  • The tool set is pinned, and the tool surface and the initialize instructions each have a byte budget; the instructions load even when a host defers tools. Record each change in the comment next to the budget. tests/conformance/test_tool_inventory.py
  • Input schemas change only on purpose: UPDATE_SNAPSHOTS=1, and the PR says why. tests/conformance/test_schema_snapshots.py
  • Every sentence of an entity description has a probe. tests/hermetic/test_description_claims.py
  • One copy of each answer, no structuredContent. tests/conformance/test_no_duplicate_payload.py
  • Entity and operation logic stays in its namespace; root modules may not gain entity names. tests/read_list/test_modular.py, tests/writes/test_dispatch_stays_generic.py
  • No telemetry from tests. tests/repo/test_telemetry_disabled_in_tests.py
  • The lint and type baselines in pyproject.toml excuse findings that predate the rules and only shrink; a new file meets the full rules, except a module of Pydantic models only, which may join the explicit-Any baseline. tests/repo/test_ratchets.py

Gotchas

  • A new module-level cache or flag needs a reset in the autouse fixture in tests/conftest.py, or tests pass or fail by run order.
  • Never author a skill outside plugins/opik/skills/. src/opik_mcp/skills is a symlink to it for the editable install. .claude/skills/ and .agents/skills/ are read by npx skills add and would ship to users. A hook and Edit(...) deny rules block Edit, Write, tee and > redirects there (checked live), but not cp or a script; make skills-verify-source in CI is the real check. The one deliberate exception is the cost intelligence guide, src/opik_mcp/cost_intelligence/cost-intelligence.md: served only in an AI Spend workspace, never published. Don't move it.
  • Permission deny rules are guard rails, not a boundary (git -C . push gets past them). Branch protection on main is the real guard.
  • Start the Claude Code session inside the worktree you are changing. Hooks, rules, agents and commands load from the session's project, not from the files you edit.
  • The package's _version.py is generated by make version. Change version.txt.
  • docs/ tracks only README.md, docs/<feature>/design-doc.md and docs/decisions/. Anything else there is ignored and never reaches a PR. The repo is public.

Workflow

  • Plan locally before implementing; plans are not committed.
  • A PR that changes a feature's behaviour updates its design-doc.md.
  • Before a PR that changes src/, run /dogfood; then /create-pr.
  • Writing (commits, PRs, comments, docs) is short and plain. See .claude/rules/git-workflow.md.

Opik itself

  • API contract and backend code: https://github.com/comet-ml/opik. The OpenAPI spec is apps/opik-documentation/documentation/fern/openapi/opik.yaml; endpoints are under apps/opik-backend/src/main/java/com/comet/opik/api/resources/v1/. Check there instead of guessing a field or an endpoint.
  • Product and feature context: https://www.comet.com/docs/opik/

Where to look next

  • Rules load by path from .claude/rules/: python, architecture, tool-surface, tests, skills, docs, agent-config; security and git-workflow always load.
  • Subagents: code-reviewer, understand, test-runner.
  • Commands: /install-branch, /dogfood, /create-pr, /address-pr-comments.
  • Design docs: docs/README.md, one per feature.
  • Decisions: docs/decisions/.