Skip to content

MCP integration

Dynamic tool discovery and execution model

Section titled “Dynamic tool discovery and execution model”

AOS uses a global MCP tool registry instead of hardcoded tool lists. Each feature module registers its tools, and the server later asks the registry for tool definitions and executable tools for the current request context.

Key behaviors:

  1. A feature module declares its name, description, defaultAccess, optional administrativeAccess, its tools, optional requiresUngatedAgents, and optional isEnabled.
  2. Registration rejects duplicate feature names and duplicate tool names.
  3. getToolDefinitions(context) returns tool definitions only from features enabled for that context, and only for tools accepted by that auth method.
  4. getEnabledTool(name, context) applies the same checks for execution, so hidden tools are also uncallable.
  5. getServiceTool(service, name, context) adds a same-service check before reusing the enabled-tool logic.

This means discovery is dynamic per request: the registry evaluates feature enablement and auth-method eligibility before listing or executing tools.

The bootstrap code registers only these MCP feature modules at startup:

  1. promptsFeature
  2. agentsFeature
  3. vibeLifecycleFeature
  4. coreToolsFeature
  5. ssoSetupFeature

The file also imports datasetsFeature, tracesFeature, todayInboxFeature, guardrailAlertsFeature, scoresFeature, and businessCaseFeature, but the current bootstrap function does not register them. A comment states that some of these are excluded from v0.3.0 unless registered again.

Practical implication: do not assume every imported feature is discoverable. Only registered modules can contribute tools to MCP discovery and execution.

Authorization layers for feature modules and tools

Section titled “Authorization layers for feature modules and tools”

AOS applies authorization in layers.

Module-level controls:

  1. Every feature module declares defaultAccess for projects that do not have an explicit rule.
  2. The registry comments state new modules are closed by default until a project admin opens or restricts them, while only pre-registry modules remain open by default.
  3. A feature may also provide isEnabled(context) for conditional availability.
  4. At request time, isFeatureEnabled first evaluates isEnabled and then calls serviceAllows(...) using the project service rule or module default.

Tool-level controls:

  1. User-token requests only reach tools with acceptsUserToken === true.
  2. App requests only reach tools with acceptsApp === true.
  3. API-key requests are not filtered by these two flags.
  4. The code intentionally makes non-opted-in tools hidden and uncallable for user-token and app requests.

Because the same checks are used for listing and execution, callers cannot rely on guessed tool names to bypass feature or auth-method restrictions.

A project API key is not a signed-in person. User-specific membership and ACL behavior must not be inferred from API-key access; use the supported user-delegated path when a tool needs user identity.

AOS supports an optional Bearer-token path for user-delegated MCP access. When enabled, the authenticator verifies the token and resolves it to an AOS user with live project membership.

Authentication flow:

  1. The request must present Authorization: Bearer ... and an x-agentops-project-id header.
  2. The project header must be a non-empty string with maximum length 120.
  3. The verifier checks signature, issuer, audience, lifetime, deny-list, required scope, and maximum lifetime.
  4. The token must include Entra tenantId and oid.
  5. AOS looks up a previously linked user by the unique (tenantId, objectId) pair.
  6. AOS resolves that user’s access to the named project and requires at least project:read.
  7. On success, AOS creates a ServerContext with authMethod: "user-token", plus projectId, orgId, and userId.

Failure behavior:

  • All refusals return the same unauthorized message: Unauthorized: invalid tool token or project.
  • The token is never logged, stored, or forwarded.
  • If the runtime configuration is absent, disabled, or unreadable, there is no tool-token authenticator and the route remains API-key-only.

Resulting access scope:

  • A user-token request still cannot use every tool. It can only discover and call tools that explicitly set acceptsUserToken.
  • Tools are expected to re-check the user’s membership and scope on each call rather than trusting the context alone.

App-authenticated service calls are separately gated

Section titled “App-authenticated service calls are separately gated”

AOS distinguishes app-authenticated calls from user-delegated calls.

What the context shows:

  1. authMethod: "app" identifies a runtime app calling through env.AOS.callService.
  2. appId is set only by AOS after it checked the enrolled host, the app’s grant, and the project’s service rule.
  3. Tool execution for app requests is opt-in per tool through acceptsApp === true.
  4. getServiceTool(service, name, context) additionally requires the tool to belong to the named service before applying normal enabled-tool checks.

Practical implication: app access is not equivalent to API-key access and is not implied by user-token support. Each tool must opt in separately.

Transport behavior and request handling ceilings

Section titled “Transport behavior and request handling ceilings”

The MCP HTTP transport in AOS is stateless and uses JSON-RPC over the Streamable HTTP transport.

Supported methods:

  1. POST for JSON-RPC requests such as initialization and tool calls.
  2. GET is delegated to the SDK transport; its optional SSE support is not a guarantee of persistent server-initiated sessions in this stateless configuration.
  3. DELETE for session termination, which the comment says returns 405 for stateless mode.
  4. OPTIONS for CORS preflight.

Request requirements and defaults:

  1. For POST, the Accept header must include application/json, text/event-stream, or */*; otherwise AOS returns 406 with a JSON-RPC error.
  2. The transport is created with sessionIdGenerator: undefined, so it runs in stateless mode.
  3. enableJsonResponse: true is enabled.
  4. On transport errors, if headers were not sent, AOS returns a JSON-RPC internal error response.

For tool tokens, the code also enforces a technical ceiling on the project header: maximum length 120 characters.

To add a feature inside the AOS codebase:

  1. Implement a module matching McpFeatureModule, including its access default.
  2. Supply complete tool definitions with input schemas and handlers returning the actual MCP result type. A tool name and an arbitrary JSON return value are not a complete implementation.
  3. Opt into acceptsUserToken or acceptsApp only after implementing the corresponding authorization checks.
  4. Register the module through the bootstrap registry. Importing the module alone does not enable its tools.

Example: what a successful user-token context contains

const context = {
authMethod: "user-token",
projectId: "PROJECT_ID",
orgId: "ORG_ID",
userId: "USER_ID",
apiKeyId: "",
publicKey: "",
accessLevel: "project",
};

This matches the successful return shape from the tool-token authenticator.

Example: Bearer auth requirements that are explicit in code

Authorization: Bearer TOKEN_VALUE
x-agentops-project-id: PROJECT_ID

Do not assume or document any connection URL from these sources alone. The supplied code documents transport behavior and auth handling, but not a public endpoint path.