@mastra/mcp 1.17.4-alpha.0 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-connections-connect-mcp-client.md +211 -0
- package/dist/docs/references/reference-tools-mcp-server.md +28 -0
- package/dist/index.cjs +713 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +715 -12
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/mastra-api-mcp-server.d.ts +32 -0
- package/dist/server/mastra-api-mcp-server.d.ts.map +1 -0
- package/dist/server/mastra-api-operations.generated.d.ts +382 -0
- package/dist/server/mastra-api-operations.generated.d.ts.map +1 -0
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -9830,7 +9830,7 @@ var AiSdkSchemaWrapper = class {
|
|
|
9830
9830
|
* const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
|
|
9831
9831
|
* ```
|
|
9832
9832
|
*/
|
|
9833
|
-
function toStandardSchema$
|
|
9833
|
+
function toStandardSchema$5(schema) {
|
|
9834
9834
|
return new AiSdkSchemaWrapper(schema);
|
|
9835
9835
|
}
|
|
9836
9836
|
//#endregion
|
|
@@ -16779,7 +16779,7 @@ var JsonSchemaWrapper = class {
|
|
|
16779
16779
|
* const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
|
|
16780
16780
|
* ```
|
|
16781
16781
|
*/
|
|
16782
|
-
function toStandardSchema$
|
|
16782
|
+
function toStandardSchema$4(schema, options) {
|
|
16783
16783
|
return new JsonSchemaWrapper(schema, options);
|
|
16784
16784
|
}
|
|
16785
16785
|
//#endregion
|
|
@@ -16855,7 +16855,7 @@ function convertToJsonSchema$1(zodSchema, options) {
|
|
|
16855
16855
|
* const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
|
|
16856
16856
|
* ```
|
|
16857
16857
|
*/
|
|
16858
|
-
function toStandardSchema$
|
|
16858
|
+
function toStandardSchema$3(zodSchema) {
|
|
16859
16859
|
const wrapper = Object.create(zodSchema);
|
|
16860
16860
|
const existingStandard = zodSchema["~standard"];
|
|
16861
16861
|
const jsonSchemaConverter = {
|
|
@@ -17007,18 +17007,18 @@ function isZodV3(schema) {
|
|
|
17007
17007
|
}
|
|
17008
17008
|
return schema instanceof v3_default.ZodType;
|
|
17009
17009
|
}
|
|
17010
|
-
function toStandardSchema(schema) {
|
|
17010
|
+
function toStandardSchema$2(schema) {
|
|
17011
17011
|
if (isZodV4(schema)) patchRecordSchemas(schema);
|
|
17012
17012
|
if (isStandardSchemaWithJSON$2(schema)) return schema;
|
|
17013
17013
|
if (isZodV4(schema)) return toStandardSchema$1(schema, {
|
|
17014
17014
|
unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,
|
|
17015
17015
|
override: JSON_SCHEMA_LIBRARY_OPTIONS.override
|
|
17016
17016
|
});
|
|
17017
|
-
if (isZodV3(schema)) return toStandardSchema$
|
|
17018
|
-
if (isVercelSchema(schema)) return toStandardSchema$
|
|
17017
|
+
if (isZodV3(schema)) return toStandardSchema$3(schema);
|
|
17018
|
+
if (isVercelSchema(schema)) return toStandardSchema$5(schema);
|
|
17019
17019
|
if (schema === null || typeof schema !== "object" && typeof schema !== "function") throw new Error(`Unsupported schema type: ${typeof schema}`);
|
|
17020
17020
|
if (typeof schema === "function") throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);
|
|
17021
|
-
return toStandardSchema$
|
|
17021
|
+
return toStandardSchema$4(schema);
|
|
17022
17022
|
}
|
|
17023
17023
|
/**
|
|
17024
17024
|
* Type guard to check if a value implements the StandardSchemaV1 interface.
|
|
@@ -22416,7 +22416,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
22416
22416
|
convertOutputSchema(outputSchema) {
|
|
22417
22417
|
if (!outputSchema) return outputSchema;
|
|
22418
22418
|
return { "~standard": {
|
|
22419
|
-
...toStandardSchema("jsonSchema" in outputSchema ? outputSchema.jsonSchema : outputSchema)["~standard"],
|
|
22419
|
+
...toStandardSchema$2("jsonSchema" in outputSchema ? outputSchema.jsonSchema : outputSchema)["~standard"],
|
|
22420
22420
|
validate: (value) => ({ value })
|
|
22421
22421
|
} };
|
|
22422
22422
|
}
|
|
@@ -22537,7 +22537,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
22537
22537
|
...annotations ? { annotations } : {}
|
|
22538
22538
|
} } : {};
|
|
22539
22539
|
const rawOutputSchema = tool.outputSchema ? "jsonSchema" in tool.outputSchema ? tool.outputSchema.jsonSchema : tool.outputSchema : void 0;
|
|
22540
|
-
const outputValidator = rawOutputSchema ? toStandardSchema(rawOutputSchema) : void 0;
|
|
22540
|
+
const outputValidator = rawOutputSchema ? toStandardSchema$2(rawOutputSchema) : void 0;
|
|
22541
22541
|
const mastraTool = (0, _mastra_core_tools.createTool)({
|
|
22542
22542
|
id: `${this.name}_${tool.name}`,
|
|
22543
22543
|
description: tool.description || "",
|
|
@@ -27399,6 +27399,709 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
27399
27399
|
}
|
|
27400
27400
|
};
|
|
27401
27401
|
//#endregion
|
|
27402
|
+
//#region src/server/mastra-api-operations.generated.ts
|
|
27403
|
+
const MASTRA_API_OPERATIONS = [
|
|
27404
|
+
{
|
|
27405
|
+
name: "agent_list",
|
|
27406
|
+
description: "List available agents",
|
|
27407
|
+
method: "GET",
|
|
27408
|
+
path: "/agents",
|
|
27409
|
+
destructive: false
|
|
27410
|
+
},
|
|
27411
|
+
{
|
|
27412
|
+
name: "agent_get",
|
|
27413
|
+
description: "Get agent details",
|
|
27414
|
+
method: "GET",
|
|
27415
|
+
path: "/agents/:agentId",
|
|
27416
|
+
destructive: false
|
|
27417
|
+
},
|
|
27418
|
+
{
|
|
27419
|
+
name: "agent_run",
|
|
27420
|
+
description: "Run an agent with JSON input",
|
|
27421
|
+
method: "POST",
|
|
27422
|
+
path: "/agents/:agentId/generate",
|
|
27423
|
+
destructive: true
|
|
27424
|
+
},
|
|
27425
|
+
{
|
|
27426
|
+
name: "workflow_list",
|
|
27427
|
+
description: "List available workflows",
|
|
27428
|
+
method: "GET",
|
|
27429
|
+
path: "/workflows",
|
|
27430
|
+
destructive: false
|
|
27431
|
+
},
|
|
27432
|
+
{
|
|
27433
|
+
name: "workflow_get",
|
|
27434
|
+
description: "Get workflow details",
|
|
27435
|
+
method: "GET",
|
|
27436
|
+
path: "/workflows/:workflowId",
|
|
27437
|
+
destructive: false
|
|
27438
|
+
},
|
|
27439
|
+
{
|
|
27440
|
+
name: "workflow_run_start",
|
|
27441
|
+
description: "Start a workflow run",
|
|
27442
|
+
method: "POST",
|
|
27443
|
+
path: "/workflows/:workflowId/start-async",
|
|
27444
|
+
destructive: true
|
|
27445
|
+
},
|
|
27446
|
+
{
|
|
27447
|
+
name: "workflow_run_list",
|
|
27448
|
+
description: "List workflow runs",
|
|
27449
|
+
method: "GET",
|
|
27450
|
+
path: "/workflows/:workflowId/runs",
|
|
27451
|
+
destructive: false
|
|
27452
|
+
},
|
|
27453
|
+
{
|
|
27454
|
+
name: "workflow_run_get",
|
|
27455
|
+
description: "Get workflow run details",
|
|
27456
|
+
method: "GET",
|
|
27457
|
+
path: "/workflows/:workflowId/runs/:runId",
|
|
27458
|
+
destructive: false
|
|
27459
|
+
},
|
|
27460
|
+
{
|
|
27461
|
+
name: "workflow_run_resume",
|
|
27462
|
+
description: "Resume a suspended workflow run",
|
|
27463
|
+
method: "POST",
|
|
27464
|
+
path: "/workflows/:workflowId/resume-async",
|
|
27465
|
+
destructive: true
|
|
27466
|
+
},
|
|
27467
|
+
{
|
|
27468
|
+
name: "workflow_run_cancel",
|
|
27469
|
+
description: "Cancel a workflow run",
|
|
27470
|
+
method: "POST",
|
|
27471
|
+
path: "/workflows/:workflowId/runs/:runId/cancel",
|
|
27472
|
+
destructive: true
|
|
27473
|
+
},
|
|
27474
|
+
{
|
|
27475
|
+
name: "tool_list",
|
|
27476
|
+
description: "List available tools",
|
|
27477
|
+
method: "GET",
|
|
27478
|
+
path: "/tools",
|
|
27479
|
+
destructive: false
|
|
27480
|
+
},
|
|
27481
|
+
{
|
|
27482
|
+
name: "tool_get",
|
|
27483
|
+
description: "Get tool details and input schema",
|
|
27484
|
+
method: "GET",
|
|
27485
|
+
path: "/tools/:toolId",
|
|
27486
|
+
destructive: false
|
|
27487
|
+
},
|
|
27488
|
+
{
|
|
27489
|
+
name: "tool_execute",
|
|
27490
|
+
description: "Execute a tool with JSON input",
|
|
27491
|
+
method: "POST",
|
|
27492
|
+
path: "/tools/:toolId/execute",
|
|
27493
|
+
destructive: true
|
|
27494
|
+
},
|
|
27495
|
+
{
|
|
27496
|
+
name: "mcp_list",
|
|
27497
|
+
description: "List MCP servers",
|
|
27498
|
+
method: "GET",
|
|
27499
|
+
path: "/mcp/v0/servers",
|
|
27500
|
+
destructive: false
|
|
27501
|
+
},
|
|
27502
|
+
{
|
|
27503
|
+
name: "mcp_get",
|
|
27504
|
+
description: "Get MCP server details",
|
|
27505
|
+
method: "GET",
|
|
27506
|
+
path: "/mcp/v0/servers/:id",
|
|
27507
|
+
destructive: false
|
|
27508
|
+
},
|
|
27509
|
+
{
|
|
27510
|
+
name: "mcp_tool_list",
|
|
27511
|
+
description: "List tools for an MCP server",
|
|
27512
|
+
method: "GET",
|
|
27513
|
+
path: "/mcp/:serverId/tools",
|
|
27514
|
+
destructive: false
|
|
27515
|
+
},
|
|
27516
|
+
{
|
|
27517
|
+
name: "mcp_tool_get",
|
|
27518
|
+
description: "Get MCP tool details",
|
|
27519
|
+
method: "GET",
|
|
27520
|
+
path: "/mcp/:serverId/tools/:toolId",
|
|
27521
|
+
destructive: false
|
|
27522
|
+
},
|
|
27523
|
+
{
|
|
27524
|
+
name: "mcp_tool_execute",
|
|
27525
|
+
description: "Execute an MCP tool with JSON input",
|
|
27526
|
+
method: "POST",
|
|
27527
|
+
path: "/mcp/:serverId/tools/:toolId/execute",
|
|
27528
|
+
destructive: true
|
|
27529
|
+
},
|
|
27530
|
+
{
|
|
27531
|
+
name: "thread_list",
|
|
27532
|
+
description: "List memory threads",
|
|
27533
|
+
method: "GET",
|
|
27534
|
+
path: "/memory/threads",
|
|
27535
|
+
destructive: false
|
|
27536
|
+
},
|
|
27537
|
+
{
|
|
27538
|
+
name: "thread_get",
|
|
27539
|
+
description: "Get thread details",
|
|
27540
|
+
method: "GET",
|
|
27541
|
+
path: "/memory/threads/:threadId",
|
|
27542
|
+
destructive: false
|
|
27543
|
+
},
|
|
27544
|
+
{
|
|
27545
|
+
name: "thread_create",
|
|
27546
|
+
description: "Create a memory thread",
|
|
27547
|
+
method: "POST",
|
|
27548
|
+
path: "/memory/threads",
|
|
27549
|
+
destructive: true
|
|
27550
|
+
},
|
|
27551
|
+
{
|
|
27552
|
+
name: "thread_update",
|
|
27553
|
+
description: "Update a memory thread",
|
|
27554
|
+
method: "PATCH",
|
|
27555
|
+
path: "/memory/threads/:threadId",
|
|
27556
|
+
destructive: true
|
|
27557
|
+
},
|
|
27558
|
+
{
|
|
27559
|
+
name: "thread_delete",
|
|
27560
|
+
description: "Delete a memory thread",
|
|
27561
|
+
method: "DELETE",
|
|
27562
|
+
path: "/memory/threads/:threadId",
|
|
27563
|
+
destructive: true
|
|
27564
|
+
},
|
|
27565
|
+
{
|
|
27566
|
+
name: "thread_messages",
|
|
27567
|
+
description: "List messages in a memory thread",
|
|
27568
|
+
method: "GET",
|
|
27569
|
+
path: "/memory/threads/:threadId/messages",
|
|
27570
|
+
destructive: false
|
|
27571
|
+
},
|
|
27572
|
+
{
|
|
27573
|
+
name: "memory_search",
|
|
27574
|
+
description: "Search long-term memory",
|
|
27575
|
+
method: "GET",
|
|
27576
|
+
path: "/memory/search",
|
|
27577
|
+
destructive: false
|
|
27578
|
+
},
|
|
27579
|
+
{
|
|
27580
|
+
name: "memory_current_get",
|
|
27581
|
+
description: "Get current working memory",
|
|
27582
|
+
method: "GET",
|
|
27583
|
+
path: "/memory/threads/:threadId/working-memory",
|
|
27584
|
+
destructive: false
|
|
27585
|
+
},
|
|
27586
|
+
{
|
|
27587
|
+
name: "memory_current_update",
|
|
27588
|
+
description: "Update current working memory",
|
|
27589
|
+
method: "POST",
|
|
27590
|
+
path: "/memory/threads/:threadId/working-memory",
|
|
27591
|
+
destructive: true
|
|
27592
|
+
},
|
|
27593
|
+
{
|
|
27594
|
+
name: "memory_status",
|
|
27595
|
+
description: "Get memory system status",
|
|
27596
|
+
method: "GET",
|
|
27597
|
+
path: "/memory/status",
|
|
27598
|
+
destructive: false
|
|
27599
|
+
},
|
|
27600
|
+
{
|
|
27601
|
+
name: "trace_list",
|
|
27602
|
+
description: "List observability traces",
|
|
27603
|
+
method: "GET",
|
|
27604
|
+
path: "/observability/traces/light",
|
|
27605
|
+
verbosePath: "/observability/traces",
|
|
27606
|
+
destructive: false
|
|
27607
|
+
},
|
|
27608
|
+
{
|
|
27609
|
+
name: "trace_get",
|
|
27610
|
+
description: "Get trace details",
|
|
27611
|
+
method: "GET",
|
|
27612
|
+
path: "/observability/traces/:traceId/light",
|
|
27613
|
+
verbosePath: "/observability/traces/:traceId",
|
|
27614
|
+
destructive: false
|
|
27615
|
+
},
|
|
27616
|
+
{
|
|
27617
|
+
name: "trace_span",
|
|
27618
|
+
description: "Get a trace span",
|
|
27619
|
+
method: "GET",
|
|
27620
|
+
path: "/observability/traces/:traceId/spans/:spanId",
|
|
27621
|
+
destructive: false
|
|
27622
|
+
},
|
|
27623
|
+
{
|
|
27624
|
+
name: "trace_query",
|
|
27625
|
+
description: "Query observability traces with advanced predicates",
|
|
27626
|
+
method: "POST",
|
|
27627
|
+
path: "/observability/traces/query",
|
|
27628
|
+
destructive: true
|
|
27629
|
+
},
|
|
27630
|
+
{
|
|
27631
|
+
name: "log_list",
|
|
27632
|
+
description: "List runtime logs",
|
|
27633
|
+
method: "GET",
|
|
27634
|
+
path: "/observability/logs",
|
|
27635
|
+
destructive: false
|
|
27636
|
+
},
|
|
27637
|
+
{
|
|
27638
|
+
name: "metric_aggregate",
|
|
27639
|
+
description: "Get an aggregate metric value",
|
|
27640
|
+
method: "POST",
|
|
27641
|
+
path: "/observability/metrics/aggregate",
|
|
27642
|
+
destructive: true
|
|
27643
|
+
},
|
|
27644
|
+
{
|
|
27645
|
+
name: "metric_breakdown",
|
|
27646
|
+
description: "Get metric values grouped by a label or field",
|
|
27647
|
+
method: "POST",
|
|
27648
|
+
path: "/observability/metrics/breakdown",
|
|
27649
|
+
destructive: true
|
|
27650
|
+
},
|
|
27651
|
+
{
|
|
27652
|
+
name: "metric_timeseries",
|
|
27653
|
+
description: "Get metric values over time",
|
|
27654
|
+
method: "POST",
|
|
27655
|
+
path: "/observability/metrics/timeseries",
|
|
27656
|
+
destructive: true
|
|
27657
|
+
},
|
|
27658
|
+
{
|
|
27659
|
+
name: "metric_percentiles",
|
|
27660
|
+
description: "Get metric percentile values over time",
|
|
27661
|
+
method: "POST",
|
|
27662
|
+
path: "/observability/metrics/percentiles",
|
|
27663
|
+
destructive: true
|
|
27664
|
+
},
|
|
27665
|
+
{
|
|
27666
|
+
name: "metric_names",
|
|
27667
|
+
description: "List discovered metric names",
|
|
27668
|
+
method: "GET",
|
|
27669
|
+
path: "/observability/discovery/metric-names",
|
|
27670
|
+
destructive: false
|
|
27671
|
+
},
|
|
27672
|
+
{
|
|
27673
|
+
name: "metric_label_keys",
|
|
27674
|
+
description: "List label keys for a metric",
|
|
27675
|
+
method: "GET",
|
|
27676
|
+
path: "/observability/discovery/metric-label-keys",
|
|
27677
|
+
destructive: false
|
|
27678
|
+
},
|
|
27679
|
+
{
|
|
27680
|
+
name: "metric_label_values",
|
|
27681
|
+
description: "List label values for a metric label key",
|
|
27682
|
+
method: "GET",
|
|
27683
|
+
path: "/observability/discovery/metric-label-values",
|
|
27684
|
+
destructive: false
|
|
27685
|
+
},
|
|
27686
|
+
{
|
|
27687
|
+
name: "score_create",
|
|
27688
|
+
description: "Create a score",
|
|
27689
|
+
method: "POST",
|
|
27690
|
+
path: "/observability/scores",
|
|
27691
|
+
destructive: true
|
|
27692
|
+
},
|
|
27693
|
+
{
|
|
27694
|
+
name: "score_list",
|
|
27695
|
+
description: "List scores",
|
|
27696
|
+
method: "GET",
|
|
27697
|
+
path: "/observability/scores",
|
|
27698
|
+
destructive: false
|
|
27699
|
+
},
|
|
27700
|
+
{
|
|
27701
|
+
name: "score_get",
|
|
27702
|
+
description: "Get score details",
|
|
27703
|
+
method: "GET",
|
|
27704
|
+
path: "/observability/scores/:scoreId",
|
|
27705
|
+
destructive: false
|
|
27706
|
+
},
|
|
27707
|
+
{
|
|
27708
|
+
name: "score_delete",
|
|
27709
|
+
description: "Delete scores by ID",
|
|
27710
|
+
method: "DELETE",
|
|
27711
|
+
path: "/observability/scores",
|
|
27712
|
+
destructive: true
|
|
27713
|
+
},
|
|
27714
|
+
{
|
|
27715
|
+
name: "feedback_delete",
|
|
27716
|
+
description: "Delete feedback by ID",
|
|
27717
|
+
method: "DELETE",
|
|
27718
|
+
path: "/observability/feedback",
|
|
27719
|
+
destructive: true
|
|
27720
|
+
},
|
|
27721
|
+
{
|
|
27722
|
+
name: "dataset_list",
|
|
27723
|
+
description: "List datasets",
|
|
27724
|
+
method: "GET",
|
|
27725
|
+
path: "/datasets",
|
|
27726
|
+
destructive: false
|
|
27727
|
+
},
|
|
27728
|
+
{
|
|
27729
|
+
name: "dataset_get",
|
|
27730
|
+
description: "Get dataset details",
|
|
27731
|
+
method: "GET",
|
|
27732
|
+
path: "/datasets/:datasetId",
|
|
27733
|
+
destructive: false
|
|
27734
|
+
},
|
|
27735
|
+
{
|
|
27736
|
+
name: "dataset_create",
|
|
27737
|
+
description: "Create a dataset",
|
|
27738
|
+
method: "POST",
|
|
27739
|
+
path: "/datasets",
|
|
27740
|
+
destructive: true
|
|
27741
|
+
},
|
|
27742
|
+
{
|
|
27743
|
+
name: "dataset_items",
|
|
27744
|
+
description: "List dataset items",
|
|
27745
|
+
method: "GET",
|
|
27746
|
+
path: "/datasets/:datasetId/items",
|
|
27747
|
+
destructive: false
|
|
27748
|
+
},
|
|
27749
|
+
{
|
|
27750
|
+
name: "experiment_list",
|
|
27751
|
+
description: "List dataset experiments",
|
|
27752
|
+
method: "GET",
|
|
27753
|
+
path: "/datasets/:datasetId/experiments",
|
|
27754
|
+
destructive: false
|
|
27755
|
+
},
|
|
27756
|
+
{
|
|
27757
|
+
name: "experiment_get",
|
|
27758
|
+
description: "Get experiment details",
|
|
27759
|
+
method: "GET",
|
|
27760
|
+
path: "/datasets/:datasetId/experiments/:experimentId",
|
|
27761
|
+
destructive: false
|
|
27762
|
+
},
|
|
27763
|
+
{
|
|
27764
|
+
name: "experiment_run",
|
|
27765
|
+
description: "Run a dataset experiment",
|
|
27766
|
+
method: "POST",
|
|
27767
|
+
path: "/datasets/:datasetId/experiments",
|
|
27768
|
+
destructive: true
|
|
27769
|
+
},
|
|
27770
|
+
{
|
|
27771
|
+
name: "experiment_results",
|
|
27772
|
+
description: "List experiment results",
|
|
27773
|
+
method: "GET",
|
|
27774
|
+
path: "/datasets/:datasetId/experiments/:experimentId/results",
|
|
27775
|
+
destructive: false
|
|
27776
|
+
},
|
|
27777
|
+
{
|
|
27778
|
+
name: "learning_entities",
|
|
27779
|
+
description: "List entities with Trace Intelligence output",
|
|
27780
|
+
method: "GET",
|
|
27781
|
+
path: "/learning/entities",
|
|
27782
|
+
destructive: false
|
|
27783
|
+
},
|
|
27784
|
+
{
|
|
27785
|
+
name: "learning_snapshots",
|
|
27786
|
+
description: "List analysis snapshots for an entity and ordered trace signals",
|
|
27787
|
+
method: "GET",
|
|
27788
|
+
path: "/learning/entities/:entityId/theme-snapshots",
|
|
27789
|
+
destructive: false
|
|
27790
|
+
},
|
|
27791
|
+
{
|
|
27792
|
+
name: "learning_flow",
|
|
27793
|
+
description: "Get the cross-signal theme flow for one snapshot",
|
|
27794
|
+
method: "GET",
|
|
27795
|
+
path: "/learning/entities/:entityId/theme-flow",
|
|
27796
|
+
destructive: false
|
|
27797
|
+
},
|
|
27798
|
+
{
|
|
27799
|
+
name: "learning_paths",
|
|
27800
|
+
description: "Get per-trace theme assignments for one snapshot",
|
|
27801
|
+
method: "GET",
|
|
27802
|
+
path: "/learning/entities/:entityId/theme-paths",
|
|
27803
|
+
destructive: false
|
|
27804
|
+
},
|
|
27805
|
+
{
|
|
27806
|
+
name: "learning_theme_list",
|
|
27807
|
+
description: "List themes for one trace signal in one snapshot",
|
|
27808
|
+
method: "GET",
|
|
27809
|
+
path: "/learning/entities/:entityId/themes",
|
|
27810
|
+
destructive: false
|
|
27811
|
+
},
|
|
27812
|
+
{
|
|
27813
|
+
name: "learning_theme_get",
|
|
27814
|
+
description: "Get one theme in one snapshot",
|
|
27815
|
+
method: "GET",
|
|
27816
|
+
path: "/learning/entities/:entityId/themes/:themeId",
|
|
27817
|
+
destructive: false
|
|
27818
|
+
},
|
|
27819
|
+
{
|
|
27820
|
+
name: "learning_theme_examples",
|
|
27821
|
+
description: "List trace examples for one theme in one snapshot",
|
|
27822
|
+
method: "GET",
|
|
27823
|
+
path: "/learning/entities/:entityId/themes/:themeId/examples",
|
|
27824
|
+
destructive: false
|
|
27825
|
+
},
|
|
27826
|
+
{
|
|
27827
|
+
name: "learning_theme_history",
|
|
27828
|
+
description: "Get lifecycle history for one durable theme",
|
|
27829
|
+
method: "GET",
|
|
27830
|
+
path: "/learning/entities/:entityId/themes/:themeId/history",
|
|
27831
|
+
destructive: false
|
|
27832
|
+
},
|
|
27833
|
+
{
|
|
27834
|
+
name: "learning_noise_get",
|
|
27835
|
+
description: "Get the noise bucket for one trace signal in one snapshot",
|
|
27836
|
+
method: "GET",
|
|
27837
|
+
path: "/learning/entities/:entityId/noise",
|
|
27838
|
+
destructive: false
|
|
27839
|
+
},
|
|
27840
|
+
{
|
|
27841
|
+
name: "learning_noise_examples",
|
|
27842
|
+
description: "List trace examples for the noise bucket in one snapshot",
|
|
27843
|
+
method: "GET",
|
|
27844
|
+
path: "/learning/entities/:entityId/noise/examples",
|
|
27845
|
+
destructive: false
|
|
27846
|
+
}
|
|
27847
|
+
];
|
|
27848
|
+
//#endregion
|
|
27849
|
+
//#region src/server/mastra-api-mcp-server.ts
|
|
27850
|
+
var MastraApiRequester = class {
|
|
27851
|
+
options;
|
|
27852
|
+
constructor(options) {
|
|
27853
|
+
this.options = options;
|
|
27854
|
+
}
|
|
27855
|
+
async getSchemaManifest() {
|
|
27856
|
+
const value = await this.request({
|
|
27857
|
+
method: "GET",
|
|
27858
|
+
path: "/system/api-schema",
|
|
27859
|
+
pathParamSchema: void 0,
|
|
27860
|
+
queryParamSchema: void 0,
|
|
27861
|
+
bodySchema: void 0
|
|
27862
|
+
}, {});
|
|
27863
|
+
if (!isRecord(value) || value.version !== 1 || !Array.isArray(value.routes)) throw new Error("The Mastra server returned an invalid API schema manifest. Confirm that the target server supports GET /api/system/api-schema.");
|
|
27864
|
+
const routes = value.routes.filter(isApiSchemaRoute);
|
|
27865
|
+
if (routes.length !== value.routes.length) throw new Error("The Mastra server API schema manifest contains an invalid route definition.");
|
|
27866
|
+
return routes;
|
|
27867
|
+
}
|
|
27868
|
+
async request(route, input, authInfo, requestSignal) {
|
|
27869
|
+
const pathParams = schemaPropertyNames(route.pathParamSchema);
|
|
27870
|
+
const queryParams = new Set(schemaPropertyNames(route.queryParamSchema));
|
|
27871
|
+
const bodyParams = new Set(schemaPropertyNames(route.bodySchema));
|
|
27872
|
+
const remainingInput = { ...input };
|
|
27873
|
+
let path = route.path;
|
|
27874
|
+
for (const name of pathParams) {
|
|
27875
|
+
path = path.replace(`:${name}`, encodeURIComponent(remainingInput[name]));
|
|
27876
|
+
delete remainingInput[name];
|
|
27877
|
+
}
|
|
27878
|
+
const url = new URL(joinUrl(this.options.baseUrl, this.options.apiPrefix, path));
|
|
27879
|
+
const body = {};
|
|
27880
|
+
for (const [name, value] of Object.entries(remainingInput)) {
|
|
27881
|
+
if (value === void 0) continue;
|
|
27882
|
+
if (route.method === "GET" || queryParams.has(name) && !bodyParams.has(name)) {
|
|
27883
|
+
if (value === null) continue;
|
|
27884
|
+
url.searchParams.set(name, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
27885
|
+
} else body[name] = value;
|
|
27886
|
+
}
|
|
27887
|
+
const headers = new Headers(this.options.headers);
|
|
27888
|
+
headers.set("accept", "application/json");
|
|
27889
|
+
const callerToken = getAuthToken(authInfo);
|
|
27890
|
+
if (callerToken) headers.set("authorization", `Bearer ${callerToken}`);
|
|
27891
|
+
const controller = new AbortController();
|
|
27892
|
+
const timeout = setTimeout(() => controller.abort(/* @__PURE__ */ new Error("request timed out")), this.options.timeoutMs);
|
|
27893
|
+
const abortRequest = () => controller.abort(requestSignal?.reason);
|
|
27894
|
+
if (requestSignal?.aborted) abortRequest();
|
|
27895
|
+
else requestSignal?.addEventListener("abort", abortRequest, { once: true });
|
|
27896
|
+
try {
|
|
27897
|
+
const hasBody = route.method !== "GET" && route.bodySchema !== void 0;
|
|
27898
|
+
if (hasBody) headers.set("content-type", "application/json");
|
|
27899
|
+
const response = await this.options.fetch(url, {
|
|
27900
|
+
method: route.method,
|
|
27901
|
+
headers,
|
|
27902
|
+
signal: controller.signal,
|
|
27903
|
+
...hasBody ? { body: JSON.stringify(body) } : {}
|
|
27904
|
+
});
|
|
27905
|
+
const responseBody = await readResponseBody(response);
|
|
27906
|
+
if (!response.ok) {
|
|
27907
|
+
const detail = getErrorDetail(responseBody);
|
|
27908
|
+
throw new Error(`Mastra API request ${route.method} ${route.path} failed with status ${response.status}${detail ? `: ${detail}` : "."}`);
|
|
27909
|
+
}
|
|
27910
|
+
return responseBody;
|
|
27911
|
+
} catch (error) {
|
|
27912
|
+
if (controller.signal.aborted) {
|
|
27913
|
+
if (requestSignal?.aborted) throw new Error(`Mastra API request ${route.method} ${route.path} was canceled.`, { cause: error });
|
|
27914
|
+
throw new Error(`Mastra API request ${route.method} ${route.path} timed out after ${this.options.timeoutMs}ms.`, { cause: error });
|
|
27915
|
+
}
|
|
27916
|
+
if (error instanceof Error && error.message.startsWith("Mastra API request ")) throw error;
|
|
27917
|
+
throw new Error(`Could not reach the Mastra server at ${this.options.baseUrl}. Check the server URL and network access.`, { cause: error });
|
|
27918
|
+
} finally {
|
|
27919
|
+
clearTimeout(timeout);
|
|
27920
|
+
requestSignal?.removeEventListener("abort", abortRequest);
|
|
27921
|
+
}
|
|
27922
|
+
}
|
|
27923
|
+
};
|
|
27924
|
+
/**
|
|
27925
|
+
* An MCP server that exposes the Mastra API CLI operations from a remote Mastra server.
|
|
27926
|
+
*
|
|
27927
|
+
* The factory reads the target server's schema manifest, registers the CLI operations
|
|
27928
|
+
* supported by that server, and uses the route schemas as MCP tool input schemas.
|
|
27929
|
+
*/
|
|
27930
|
+
var MastraApiMCPServer = class MastraApiMCPServer extends MCPServer {
|
|
27931
|
+
constructor(options, tools) {
|
|
27932
|
+
super({
|
|
27933
|
+
id: options.id ?? "mastra-api",
|
|
27934
|
+
name: options.name ?? "Mastra Server",
|
|
27935
|
+
version: options.version ?? "1.0.0",
|
|
27936
|
+
description: "Inspect and operate a Mastra server.",
|
|
27937
|
+
instructions: "Inspect resources before using them. Pass tool input inside the data field for tool_execute and mcp_tool_execute. Ask for confirmation before calling a tool marked as destructive.",
|
|
27938
|
+
protocolVersion: "2026-07-28",
|
|
27939
|
+
tools
|
|
27940
|
+
});
|
|
27941
|
+
}
|
|
27942
|
+
/** Creates a stateless MCP server for the target Mastra server. */
|
|
27943
|
+
static async create(options) {
|
|
27944
|
+
const requester = new MastraApiRequester(normalizeOptions(options));
|
|
27945
|
+
const tools = createApiTools(await requester.getSchemaManifest(), requester);
|
|
27946
|
+
if (Object.keys(tools).length === 0) throw new Error("The target Mastra server does not support any of the MCP server operations.");
|
|
27947
|
+
return new MastraApiMCPServer(options, tools);
|
|
27948
|
+
}
|
|
27949
|
+
};
|
|
27950
|
+
function createApiTools(routes, requester) {
|
|
27951
|
+
const tools = {};
|
|
27952
|
+
for (const operation of MASTRA_API_OPERATIONS) {
|
|
27953
|
+
const primaryRoute = routes.find((candidate) => candidate.method === operation.method && candidate.path === operation.path);
|
|
27954
|
+
const verboseRoute = "verbosePath" in operation ? routes.find((candidate) => candidate.method === operation.method && candidate.path === operation.verbosePath) : void 0;
|
|
27955
|
+
const route = primaryRoute ?? verboseRoute;
|
|
27956
|
+
if (!route) continue;
|
|
27957
|
+
const readOnly = operation.method === "GET";
|
|
27958
|
+
tools[operation.name] = (0, _mastra_core_tools.createTool)({
|
|
27959
|
+
id: operation.name,
|
|
27960
|
+
description: operation.description,
|
|
27961
|
+
inputSchema: (0, _mastra_core_schema.toStandardSchema)(mergeInputSchemas(route, primaryRoute !== void 0 && verboseRoute !== void 0)),
|
|
27962
|
+
mcp: { annotations: {
|
|
27963
|
+
title: operation.description,
|
|
27964
|
+
readOnlyHint: readOnly,
|
|
27965
|
+
destructiveHint: operation.destructive,
|
|
27966
|
+
idempotentHint: readOnly || operation.method === "DELETE",
|
|
27967
|
+
openWorldHint: true
|
|
27968
|
+
} },
|
|
27969
|
+
execute: async (input, context) => {
|
|
27970
|
+
let requestInput = input;
|
|
27971
|
+
let selectedRoute = route;
|
|
27972
|
+
if (primaryRoute && verboseRoute) {
|
|
27973
|
+
const { verbose, ...inputWithoutVerbose } = input;
|
|
27974
|
+
requestInput = inputWithoutVerbose;
|
|
27975
|
+
if (verbose === true) selectedRoute = verboseRoute;
|
|
27976
|
+
}
|
|
27977
|
+
return requester.request(selectedRoute, requestInput, context.mcp?.extra.authInfo ?? getRequestAuthInfo(context.requestContext), context.abortSignal ?? context.mcp?.extra.signal);
|
|
27978
|
+
}
|
|
27979
|
+
});
|
|
27980
|
+
}
|
|
27981
|
+
return tools;
|
|
27982
|
+
}
|
|
27983
|
+
function normalizeOptions(options) {
|
|
27984
|
+
let url;
|
|
27985
|
+
try {
|
|
27986
|
+
url = new URL(options.url);
|
|
27987
|
+
} catch (error) {
|
|
27988
|
+
throw new Error("The Mastra server URL must be a valid absolute URL.", { cause: error });
|
|
27989
|
+
}
|
|
27990
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error("The Mastra server URL must use HTTP or HTTPS.");
|
|
27991
|
+
if (url.username || url.password) throw new Error("The Mastra server URL cannot contain credentials. Use the headers option for authentication.");
|
|
27992
|
+
if (url.search || url.hash) throw new Error("The Mastra server URL cannot contain a query string or fragment.");
|
|
27993
|
+
const apiPrefix = normalizeApiPrefix(options.apiPrefix ?? "/api");
|
|
27994
|
+
const timeoutMs = options.timeoutMs ?? 12e4;
|
|
27995
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) throw new Error("The request timeout must be a positive integer in milliseconds.");
|
|
27996
|
+
return {
|
|
27997
|
+
baseUrl: url.toString().replace(/\/$/, ""),
|
|
27998
|
+
apiPrefix,
|
|
27999
|
+
headers: { ...options.headers },
|
|
28000
|
+
timeoutMs,
|
|
28001
|
+
fetch: options.fetch ?? globalThis.fetch
|
|
28002
|
+
};
|
|
28003
|
+
}
|
|
28004
|
+
function normalizeApiPrefix(value) {
|
|
28005
|
+
if (value.includes("..") || value.includes("?") || value.includes("#")) throw new Error("The Mastra API prefix cannot contain \"..\", a query string, or a fragment.");
|
|
28006
|
+
let start = 0;
|
|
28007
|
+
let end = value.length;
|
|
28008
|
+
while (start < end && value[start] === "/") start++;
|
|
28009
|
+
while (end > start && value[end - 1] === "/") end--;
|
|
28010
|
+
return start === end ? "" : `/${value.slice(start, end)}`;
|
|
28011
|
+
}
|
|
28012
|
+
function joinUrl(baseUrl, apiPrefix, path) {
|
|
28013
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
28014
|
+
if (!apiPrefix || baseUrl.endsWith(apiPrefix)) return `${baseUrl}${normalizedPath}`;
|
|
28015
|
+
return `${baseUrl}${apiPrefix}${normalizedPath}`;
|
|
28016
|
+
}
|
|
28017
|
+
function mergeInputSchemas(route, supportsVerbose = false) {
|
|
28018
|
+
const definitions = {};
|
|
28019
|
+
const schemas = [
|
|
28020
|
+
"pathParamSchema",
|
|
28021
|
+
"queryParamSchema",
|
|
28022
|
+
"bodySchema"
|
|
28023
|
+
].flatMap((key) => {
|
|
28024
|
+
const source = route[key];
|
|
28025
|
+
if (!isRecord(source)) return [];
|
|
28026
|
+
const schema = relocateSchemaReferences(source, `#/definitions/${key}`);
|
|
28027
|
+
definitions[key] = schema;
|
|
28028
|
+
return [schema];
|
|
28029
|
+
});
|
|
28030
|
+
const properties = {};
|
|
28031
|
+
const pathParams = new Set(schemaPropertyNames(route.pathParamSchema));
|
|
28032
|
+
const required = new Set(pathParams);
|
|
28033
|
+
let allowsAdditionalProperties = false;
|
|
28034
|
+
for (const schema of schemas) {
|
|
28035
|
+
if (isRecord(schema.properties)) for (const [name, property] of Object.entries(schema.properties)) properties[name] = pathParams.has(name) && Object.hasOwn(properties, name) ? { allOf: [properties[name], property] } : property;
|
|
28036
|
+
if (Array.isArray(schema.required)) {
|
|
28037
|
+
for (const name of schema.required) if (typeof name === "string") required.add(name);
|
|
28038
|
+
}
|
|
28039
|
+
if (schema.additionalProperties === true || isRecord(schema.additionalProperties)) allowsAdditionalProperties = true;
|
|
28040
|
+
}
|
|
28041
|
+
if (supportsVerbose) properties.verbose = {
|
|
28042
|
+
type: "boolean",
|
|
28043
|
+
description: "Return the full response instead of the lightweight response.",
|
|
28044
|
+
default: false
|
|
28045
|
+
};
|
|
28046
|
+
for (const name of pathParams) properties[name] = {
|
|
28047
|
+
type: "string",
|
|
28048
|
+
minLength: 1,
|
|
28049
|
+
allOf: [properties[name]]
|
|
28050
|
+
};
|
|
28051
|
+
return {
|
|
28052
|
+
type: "object",
|
|
28053
|
+
properties,
|
|
28054
|
+
required: [...required],
|
|
28055
|
+
additionalProperties: allowsAdditionalProperties,
|
|
28056
|
+
definitions
|
|
28057
|
+
};
|
|
28058
|
+
}
|
|
28059
|
+
function relocateSchemaReferences(value, root) {
|
|
28060
|
+
if (Array.isArray(value)) return value.map((item) => relocateSchemaReferences(item, root));
|
|
28061
|
+
if (!isRecord(value)) return value;
|
|
28062
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, key === "$ref" && typeof child === "string" && (child === "#" || child.startsWith("#/")) ? `${root}${child.slice(1)}` : relocateSchemaReferences(child, root)]));
|
|
28063
|
+
}
|
|
28064
|
+
function schemaPropertyNames(schema) {
|
|
28065
|
+
return isRecord(schema?.properties) ? Object.keys(schema.properties) : [];
|
|
28066
|
+
}
|
|
28067
|
+
function isApiSchemaRoute(value) {
|
|
28068
|
+
if (!isRecord(value) || typeof value.method !== "string" || typeof value.path !== "string") return false;
|
|
28069
|
+
return [
|
|
28070
|
+
"pathParamSchema",
|
|
28071
|
+
"queryParamSchema",
|
|
28072
|
+
"bodySchema"
|
|
28073
|
+
].every((key) => value[key] === void 0 || isRecord(value[key]));
|
|
28074
|
+
}
|
|
28075
|
+
function isRecord(value) {
|
|
28076
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28077
|
+
}
|
|
28078
|
+
function getAuthToken(authInfo) {
|
|
28079
|
+
if (!isRecord(authInfo)) return void 0;
|
|
28080
|
+
return typeof authInfo.token === "string" && authInfo.token.length > 0 ? authInfo.token : void 0;
|
|
28081
|
+
}
|
|
28082
|
+
function getRequestAuthInfo(requestContext) {
|
|
28083
|
+
const authInfo = requestContext?.get("authInfo");
|
|
28084
|
+
if (authInfo !== void 0) return authInfo;
|
|
28085
|
+
const token = requestContext?.get(_mastra_core_request_context.MASTRA_AUTH_TOKEN_KEY);
|
|
28086
|
+
return typeof token === "string" && token.length > 0 ? { token } : void 0;
|
|
28087
|
+
}
|
|
28088
|
+
async function readResponseBody(response) {
|
|
28089
|
+
const text = await response.text();
|
|
28090
|
+
if (!text) return null;
|
|
28091
|
+
try {
|
|
28092
|
+
return JSON.parse(text);
|
|
28093
|
+
} catch {
|
|
28094
|
+
return text;
|
|
28095
|
+
}
|
|
28096
|
+
}
|
|
28097
|
+
function getErrorDetail(body) {
|
|
28098
|
+
if (typeof body === "string") return body.slice(0, 500);
|
|
28099
|
+
if (!isRecord(body)) return void 0;
|
|
28100
|
+
const error = isRecord(body.error) ? body.error : body;
|
|
28101
|
+
if (typeof error.message === "string") return error.message.slice(0, 500);
|
|
28102
|
+
return JSON.stringify(body).slice(0, 500);
|
|
28103
|
+
}
|
|
28104
|
+
//#endregion
|
|
27402
28105
|
//#region src/server/oauth-middleware.ts
|
|
27403
28106
|
/**
|
|
27404
28107
|
* Creates an OAuth middleware function for protecting MCP server endpoints.
|
|
@@ -27653,6 +28356,7 @@ exports.MCPOAuthClientProvider = MCPOAuthClientProvider;
|
|
|
27653
28356
|
exports.MCPServer = MCPServer;
|
|
27654
28357
|
exports.MCP_CALL_TOOL_CONTENT = MCP_CALL_TOOL_CONTENT;
|
|
27655
28358
|
exports.MCP_CALL_TOOL_META = MCP_CALL_TOOL_META;
|
|
28359
|
+
exports.MastraApiMCPServer = MastraApiMCPServer;
|
|
27656
28360
|
Object.defineProperty(exports, "UnauthorizedError", {
|
|
27657
28361
|
enumerable: true,
|
|
27658
28362
|
get: function() {
|