Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/mcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ const handler = {
: undefined;
const withOTel = withOtelParam === '1' || withOtelParam === 'true';

// Extract trace headers for propagation to downstream services
const traceHeaders: Record<string, string> = {};
const traceHeaderNames = [
'traceparent',
'tracestate',
'x-trace-id',
'x-request-id',
];

for (const headerName of traceHeaderNames) {
const headerValue = request.headers.get(headerName);
if (headerValue) {
traceHeaders[headerName] = headerValue;
}
}

const props: ServerProps = {
tokenKey: await sha256(`${accessToken}:${orgId}`),
accessToken,
Expand All @@ -111,6 +127,8 @@ const handler = {
? (maxCells as number)
: undefined,
withOTel,
traceHeaders:
Object.keys(traceHeaders).length > 0 ? traceHeaders : undefined,
};

ctx.props = props;
Expand Down
4 changes: 3 additions & 1 deletion apps/mcp/src/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class AxiomMCP extends McpAgent<
formatOptions: this.props.maxCells
? { maxCells: this.props.maxCells }
: undefined,
traceHeaders: this.props.traceHeaders,
});

logger.info('Server initialized');
Expand All @@ -60,7 +61,8 @@ export class AxiomMCP extends McpAgent<
const internalClient = new Client(
this.env.ATLAS_INTERNAL_URL,
this.props.accessToken,
this.props.orgId
this.props.orgId,
this.props.traceHeaders
);
const ret: Integrations = await getIntegrations(internalClient);
integrations = [...new Set(ret.map((i) => i.kind))];
Expand Down
1 change: 1 addition & 0 deletions apps/mcp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export type ServerProps = {
// Parsed from `max-age` and `with-otel`
maxCells?: number;
withOTel?: boolean;
traceHeaders?: Record<string, string>;
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/mcp/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Auto-generated MCP metadata
* Generated at: 2025-10-07T14:50:49.840Z
* Generated at: 2025-10-07T08:25:05.303Z
* DO NOT EDIT - This file is automatically generated by scripts/extract-tools.ts
*/

Expand Down
22 changes: 19 additions & 3 deletions packages/mcp/src/axiom/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type ApiRequest = {
body?: unknown;
baseUrl: string;
orgId: string;
traceHeaders?: Record<string, string>;
};

// MCP server telemetry configuration - similar to axiom.SetUserAgent() in Go SDK
Expand All @@ -33,7 +34,7 @@ export async function apiFetch<T>(
areq: ApiRequest,
schema: z.ZodSchema<T>
): Promise<T> {
const { token, method, path, body, baseUrl, orgId } = areq;
const { token, method, path, body, baseUrl, orgId, traceHeaders } = areq;
const headers: Record<string, string> = {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
Expand All @@ -46,6 +47,13 @@ export async function apiFetch<T>(
headers['x-axiom-org-id'] = orgId;
}

// Propagate trace headers for distributed tracing
if (traceHeaders) {
for (const [key, value] of Object.entries(traceHeaders)) {
headers[key] = value;
}
}

const options: RequestInit = {
method,
headers,
Expand Down Expand Up @@ -89,11 +97,18 @@ export class Client {
private baseUrl: string;
private accessToken: string;
private orgId: string;

constructor(baseUrl: string, accessToken: string, orgId: string) {
private traceHeaders?: Record<string, string>;

constructor(
baseUrl: string,
accessToken: string,
orgId: string,
traceHeaders?: Record<string, string>
) {
this.baseUrl = baseUrl;
this.accessToken = accessToken;
this.orgId = orgId;
this.traceHeaders = traceHeaders;
}

async fetch<T>(
Expand All @@ -110,6 +125,7 @@ export class Client {
body,
baseUrl: this.baseUrl,
orgId: this.orgId,
traceHeaders: this.traceHeaders,
},
schema
);
Expand Down
7 changes: 5 additions & 2 deletions packages/mcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ export interface AxiomMcpConfig {
orgId: string;
enableOtel?: boolean;
formatOptions?: FormatterOptions;
traceHeaders?: Record<string, string>;
}

export function registerAxiomMcpTools(config: AxiomMcpConfig) {
const publicClient = new Client(
config.apiUrl,
config.accessToken,
config.orgId
config.orgId,
config.traceHeaders
);
const internalClient = new Client(
config.internalUrl,
config.accessToken,
config.orgId
config.orgId,
config.traceHeaders
);

const context = {
Expand Down