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
10 changes: 10 additions & 0 deletions .changeset/mcp-source-section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@hyperdx/api": patch
---

feat: include the source Section in MCP source tools

The `clickstack_list_sources` and `clickstack_describe_source` MCP tools now
return the optional Section label on each source, so agents see the same source
grouping that the source selector shows. Sources without a section are
unchanged.
32 changes: 32 additions & 0 deletions packages/api/src/mcp/__tests__/sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('MCP Source Tools', () => {
traceIdExpression: 'TraceId',
connection: connection._id,
name: 'Logs',
section: 'Billing',
});

const context: McpContext = {
Expand Down Expand Up @@ -149,6 +150,19 @@ describe('MCP Source Tools', () => {
expect(log.keyColumns).toHaveProperty('body');
});

it('includes a source section when set and omits it when unset', async () => {
const result = await callTool(client, 'clickstack_list_sources');
const output = JSON.parse(getFirstText(result));

const log = output.sources.find((s: any) => s.kind === SourceKind.Log);
expect(log.section).toBe('Billing');

const trace = output.sources.find(
(s: any) => s.kind === SourceKind.Trace,
);
expect(trace.section).toBeUndefined();
});

it('should return empty sources for a team with no sources', async () => {
await client.close();
await server.clearDBs();
Expand Down Expand Up @@ -222,6 +236,24 @@ describe('MCP Source Tools', () => {
});
});

it('includes the source section when set and omits it when unset', async () => {
const withSection = await callTool(client, 'clickstack_describe_source', {
sourceId: logSource._id.toString(),
});
expect(JSON.parse(getFirstText(withSection)).source.section).toBe(
'Billing',
);

const withoutSection = await callTool(
client,
'clickstack_describe_source',
{ sourceId: traceSource._id.toString() },
);
expect(
JSON.parse(getFirstText(withoutSection)).source.section,
).toBeUndefined();
});

it('should include map attribute keys', async () => {
const result = await callTool(client, 'clickstack_describe_source', {
sourceId: traceSource._id.toString(),
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/mcp/tools/sources/describeSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ async function describeSourceSchema(
timestampColumn: source.timestampValueExpression,
};

if (source.section) {
meta.section = source.section;
}

if (
'eventAttributesExpression' in source &&
source.eventAttributesExpression
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/mcp/tools/sources/listSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export function registerListSources(
timestampColumn: s.timestampValueExpression,
};

if (s.section) {
meta.section = s.section;
}

if ('eventAttributesExpression' in s && s.eventAttributesExpression) {
meta.eventAttributesColumn = s.eventAttributesExpression;
}
Expand Down
Loading