Skip to main content

Agnost Analytics SDK

PyPI version Python

Analytics SDK for tracking and analyzing Model Context Protocol (MCP) server interactions. Get insights into how your MCP servers are being used, monitor performance, and optimize user experiences.

Installation

pip install agnost-mcp

Basic Usage

import agnost_mcp
from fastmcp import FastMCP

# Create FastMCP server
mcp = FastMCP("My Server")

@mcp.tool()
def calculate(operation: str, a: float, b: float) -> float:
    """Perform mathematical operations."""
    if operation == "add":
        return a + b
    elif operation == "multiply":
        return a * b
    return 0

# Enable analytics tracking
agnost_mcp.track(mcp, org_id="your-organization-id")

Analytics delivery runs on a bounded background queue so tool calls do not wait for the Agnost API. Call shutdown() during application teardown to flush queued events on a best-effort basis and close the worker:

try:
    mcp.run()
finally:
    agnost_mcp.shutdown()

Configuration

You can customize the SDK behavior using the configuration object:

import agnost_mcp

# Create a custom configuration
config = agnost_mcp.config(
    endpoint="https://api.agnost.ai",
    disable_input=False,    # Set to True to disable input tracking
    disable_output=False,   # Set to True to disable output tracking
    log_level="INFO",
)

# Apply the configuration
agnost_mcp.track(
    server=server,
    org_id="your-organization-id",
    config=config
)

Configuration Options

Option Type Default Description
endpoint str "https://api.agnost.ai" Agnost API base URL
disable_input bool False Disable tracking of input arguments
disable_output bool False Disable tracking of output results
log_level str "INFO" SDK logging level
identify callable | None None Resolve per-session user identity from request context

Without a custom identify callback, HTTP transports resolve identity from the request's Authorization: Bearer ... header, falling back to the MCP server's validated auth token when headers are unavailable. JWT claims are checked in this order: sub, user_id, userId, email, preferred_username, then username. An email claim is preserved as user metadata, and opaque bearer tokens or x-api-key credentials are represented by a stable one-way hash; raw credentials are never sent to Agnost.

The identify callback may be synchronous or asynchronous. It must return a dictionary containing userId, or None to skip attribution for that attempt. Failed or anonymous results are retried instead of being cached for the process.

Stateful Streamable HTTP and SSE calls reuse their MCP session. Stateless Streamable HTTP groups calls by OAuth token/grant ID when available, then by resolved user, then by one bounded anonymous bucket. Stdio remains scoped to the server process. Multiple server instances in one process are supported when they use the same organization and config; mismatches are rejected rather than silently misattributed.

Contact

For support or questions, contact the founders: founders@agnost.ai

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agnost_mcp-0.2.0.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agnost_mcp-0.2.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file agnost_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: agnost_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for agnost_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1d13571ee0dce63f759104cd602c3afc05475eb13ea41e8f9002946054828221
MD5 aff323a3fae0cd32aabe73ab5aec8344
BLAKE2b-256 c551abdaacb4d5dae5fdc0250d9ef5e9403035003df10a5afb8d5bf403a17de4

See more details on using hashes here.

File details

Details for the file agnost_mcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: agnost_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for agnost_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25540028f33d164056ca5e83b4540cf5fa16d4134ac3171d34429e1ac4c76705
MD5 56675080d51964cfe55cef4e826ebb72
BLAKE2b-256 b2aa4397607111bf7163eeea30d70dfb50628497aa9daec269f8720fd6b1bcb5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.8

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page