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:
- A feature module declares its
name,description,defaultAccess, optionaladministrativeAccess, itstools, optionalrequiresUngatedAgents, and optionalisEnabled. - Registration rejects duplicate feature names and duplicate tool names.
getToolDefinitions(context)returns tool definitions only from features enabled for that context, and only for tools accepted by that auth method.getEnabledTool(name, context)applies the same checks for execution, so hidden tools are also uncallable.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.
Enabled feature modules at startup
Section titled “Enabled feature modules at startup”The bootstrap code registers only these MCP feature modules at startup:
promptsFeatureagentsFeaturevibeLifecycleFeaturecoreToolsFeaturessoSetupFeature
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:
- Every feature module declares
defaultAccessfor projects that do not have an explicit rule. - 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.
- A feature may also provide
isEnabled(context)for conditional availability. - At request time,
isFeatureEnabledfirst evaluatesisEnabledand then callsserviceAllows(...)using the project service rule or module default.
Tool-level controls:
- User-token requests only reach tools with
acceptsUserToken === true. - App requests only reach tools with
acceptsApp === true. - API-key requests are not filtered by these two flags.
- 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.
User-delegated access with tool tokens
Section titled “User-delegated access with tool tokens”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:
- The request must present
Authorization: Bearer ...and anx-agentops-project-idheader. - The project header must be a non-empty string with maximum length 120.
- The verifier checks signature, issuer, audience, lifetime, deny-list, required scope, and maximum lifetime.
- The token must include Entra
tenantIdandoid. - AOS looks up a previously linked user by the unique
(tenantId, objectId)pair. - AOS resolves that user’s access to the named project and requires at least
project:read. - On success, AOS creates a
ServerContextwithauthMethod: "user-token", plusprojectId,orgId, anduserId.
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:
authMethod: "app"identifies a runtime app calling throughenv.AOS.callService.appIdis set only by AOS after it checked the enrolled host, the app’s grant, and the project’s service rule.- Tool execution for app requests is opt-in per tool through
acceptsApp === true. 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:
POSTfor JSON-RPC requests such as initialization and tool calls.GETis delegated to the SDK transport; its optional SSE support is not a guarantee of persistent server-initiated sessions in this stateless configuration.DELETEfor session termination, which the comment says returns405for stateless mode.OPTIONSfor CORS preflight.
Request requirements and defaults:
- For
POST, theAcceptheader must includeapplication/json,text/event-stream, or*/*; otherwise AOS returns406with a JSON-RPC error. - The transport is created with
sessionIdGenerator: undefined, so it runs in stateless mode. enableJsonResponse: trueis enabled.- 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.
Source-backed examples for integrators
Section titled “Source-backed examples for integrators”To add a feature inside the AOS codebase:
- Implement a module matching
McpFeatureModule, including its access default. - 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.
- Opt into
acceptsUserTokenoracceptsApponly after implementing the corresponding authorization checks. - 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_VALUEx-agentops-project-id: PROJECT_IDDo 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.