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