fastmcp 4.9.1 → 4.10.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/README.md +42 -0
- package/dist/FastMCP.cjs +4 -2
- package/dist/FastMCP.cjs.map +1 -1
- package/dist/FastMCP.d.cts +68 -2
- package/dist/FastMCP.d.ts +68 -2
- package/dist/FastMCP.js +4 -2
- package/dist/{chunk-MJCWKCHZ.cjs → chunk-GF4ORBWZ.cjs} +140 -61
- package/dist/chunk-GF4ORBWZ.cjs.map +1 -0
- package/dist/{chunk-2PFUZL7I.js → chunk-MGP2FVUH.js} +96 -17
- package/dist/chunk-MGP2FVUH.js.map +1 -0
- package/dist/examples/custom-routes.cjs +2 -2
- package/dist/examples/custom-routes.js +1 -1
- package/package.json +11 -1
- package/dist/chunk-2PFUZL7I.js.map +0 -1
- package/dist/chunk-MJCWKCHZ.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -594,6 +594,48 @@ server.addTool({
|
|
|
594
594
|
});
|
|
595
595
|
```
|
|
596
596
|
|
|
597
|
+
**Plain JSON Schema Example:**
|
|
598
|
+
|
|
599
|
+
If you already have a JSON Schema — from an OpenAPI document, a config file, or
|
|
600
|
+
another server — `jsonSchemaAdapter` wraps it so it can be used directly, with
|
|
601
|
+
no schema library in between.
|
|
602
|
+
|
|
603
|
+
It requires the peer dependency `ajv`, which does the validation, plus
|
|
604
|
+
`ajv-formats` if your schema uses `format` keywords such as `email` or `uri`.
|
|
605
|
+
Both are imported the first time a tool is called, so servers that don't use
|
|
606
|
+
this pay nothing for it.
|
|
607
|
+
|
|
608
|
+
```bash
|
|
609
|
+
npm install ajv ajv-formats
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
```typescript
|
|
613
|
+
import { jsonSchemaAdapter } from "fastmcp";
|
|
614
|
+
|
|
615
|
+
server.addTool({
|
|
616
|
+
name: "fetch-json-schema",
|
|
617
|
+
description: "Fetch the content of a url (using plain JSON Schema)",
|
|
618
|
+
parameters: jsonSchemaAdapter({
|
|
619
|
+
type: "object",
|
|
620
|
+
properties: {
|
|
621
|
+
url: { type: "string", format: "uri" },
|
|
622
|
+
},
|
|
623
|
+
required: ["url"],
|
|
624
|
+
}),
|
|
625
|
+
execute: async (args) => {
|
|
626
|
+
const { url } = args as { url: string };
|
|
627
|
+
return await fetchWebpageContent(url);
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
Works for `outputSchema` too. Note that FastMCP advertises every tool schema
|
|
633
|
+
with `additionalProperties: false`, whatever your schema said — the same
|
|
634
|
+
treatment Zod and Valibot schemas get.
|
|
635
|
+
|
|
636
|
+
Unlike the schema libraries above, a plain JSON Schema carries no TypeScript
|
|
637
|
+
types, so `execute` receives `unknown` arguments. Cast or narrow them yourself.
|
|
638
|
+
|
|
597
639
|
#### Tools Without Parameters
|
|
598
640
|
|
|
599
641
|
When creating tools that don't require parameters, you have two options:
|
package/dist/FastMCP.cjs
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
var _chunkGF4ORBWZcjs = require('./chunk-GF4ORBWZ.cjs');
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
@@ -41,5 +42,6 @@ var _chunkDZYT6QAHcjs = require('./chunk-DZYT6QAH.cjs');
|
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
|
|
46
|
+
exports.AuthProvider = _chunkDZYT6QAHcjs.AuthProvider; exports.AzureProvider = _chunkDZYT6QAHcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkGF4ORBWZcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkGF4ORBWZcjs.FastMCP; exports.FastMCPSession = _chunkGF4ORBWZcjs.FastMCPSession; exports.GitHubProvider = _chunkDZYT6QAHcjs.GitHubProvider; exports.GoogleProvider = _chunkDZYT6QAHcjs.GoogleProvider; exports.OAuthProvider = _chunkDZYT6QAHcjs.OAuthProvider; exports.ServerState = _chunkGF4ORBWZcjs.ServerState; exports.UnexpectedStateError = _chunkGF4ORBWZcjs.UnexpectedStateError; exports.UserError = _chunkGF4ORBWZcjs.UserError; exports.audioContent = _chunkGF4ORBWZcjs.audioContent; exports.getAuthSession = _chunkDZYT6QAHcjs.getAuthSession; exports.imageContent = _chunkGF4ORBWZcjs.imageContent; exports.jsonSchemaAdapter = _chunkGF4ORBWZcjs.jsonSchemaAdapter; exports.requireAll = _chunkDZYT6QAHcjs.requireAll; exports.requireAny = _chunkDZYT6QAHcjs.requireAny; exports.requireAuth = _chunkDZYT6QAHcjs.requireAuth; exports.requireRole = _chunkDZYT6QAHcjs.requireRole; exports.requireScopes = _chunkDZYT6QAHcjs.requireScopes;
|
|
45
47
|
//# sourceMappingURL=FastMCP.cjs.map
|
package/dist/FastMCP.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/fastmcp/fastmcp/dist/FastMCP.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fastmcp/fastmcp/dist/FastMCP.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,inCAAC","file":"/home/runner/work/fastmcp/fastmcp/dist/FastMCP.cjs"}
|
package/dist/FastMCP.d.cts
CHANGED
|
@@ -47,6 +47,71 @@ declare class DiscoveryDocumentCache {
|
|
|
47
47
|
has(url: string): boolean;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* A plain JSON Schema object descriptor.
|
|
52
|
+
*/
|
|
53
|
+
type JsonSchemaObject = {
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
$schema?: string;
|
|
56
|
+
additionalProperties?: boolean;
|
|
57
|
+
properties?: Record<string, unknown>;
|
|
58
|
+
required?: string[];
|
|
59
|
+
type: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A Standard Schema that also carries the JSON Schema it was built from.
|
|
63
|
+
*
|
|
64
|
+
* `~standard.jsonSchema` is the Standard JSON Schema extension. Anything that
|
|
65
|
+
* knows about it — including the `xsschema` conversion FastMCP uses to build
|
|
66
|
+
* `tools/list` — reads the schema straight off the object instead of trying to
|
|
67
|
+
* derive one from a validation library it does not recognise.
|
|
68
|
+
*/
|
|
69
|
+
interface JsonSchemaStandardSchema extends StandardSchemaV1 {
|
|
70
|
+
readonly "~standard": {
|
|
71
|
+
readonly jsonSchema: {
|
|
72
|
+
readonly input: () => JsonSchemaObject;
|
|
73
|
+
readonly output: () => JsonSchemaObject;
|
|
74
|
+
};
|
|
75
|
+
} & StandardSchemaV1.Props;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Wraps a plain JSON Schema object so it can be used as a tool's `parameters`
|
|
79
|
+
* or `outputSchema`, without pulling in Zod, Valibot, or another validation
|
|
80
|
+
* library.
|
|
81
|
+
*
|
|
82
|
+
* Validation uses AJV, which is an optional peer dependency — install `ajv`
|
|
83
|
+
* (and `ajv-formats` if you use `format` keywords) to use this. It is imported
|
|
84
|
+
* on first validation, so servers that never call this pay nothing for it.
|
|
85
|
+
*
|
|
86
|
+
* Note that FastMCP applies the same strictness to every tool schema: objects
|
|
87
|
+
* are advertised with `additionalProperties: false`, whatever the input schema
|
|
88
|
+
* said.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { FastMCP, jsonSchemaAdapter } from "fastmcp";
|
|
93
|
+
*
|
|
94
|
+
* const server = new FastMCP({ name: "Example", version: "1.0.0" });
|
|
95
|
+
*
|
|
96
|
+
* server.addTool({
|
|
97
|
+
* name: "greet",
|
|
98
|
+
* description: "Greet a user",
|
|
99
|
+
* parameters: jsonSchemaAdapter({
|
|
100
|
+
* type: "object",
|
|
101
|
+
* properties: {
|
|
102
|
+
* name: { type: "string" },
|
|
103
|
+
* },
|
|
104
|
+
* required: ["name"],
|
|
105
|
+
* }),
|
|
106
|
+
* execute: async ({ name }) => `Hello, ${name}!`,
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @param schema - A plain JSON Schema object
|
|
111
|
+
* @returns A Standard Schema that validates against `schema`
|
|
112
|
+
*/
|
|
113
|
+
declare function jsonSchemaAdapter(schema: JsonSchemaObject): JsonSchemaStandardSchema;
|
|
114
|
+
|
|
50
115
|
interface Logger {
|
|
51
116
|
debug(...args: unknown[]): void;
|
|
52
117
|
error(...args: unknown[]): void;
|
|
@@ -726,7 +791,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
|
|
|
726
791
|
get server(): Server;
|
|
727
792
|
get sessionId(): string | undefined;
|
|
728
793
|
set sessionId(value: string | undefined);
|
|
729
|
-
constructor({ auth, instructions, logger, name, onToolCall, ping, prompts, resources, resourcesTemplates, roots, sessionId, tools, transportType, utils, version, }: {
|
|
794
|
+
constructor({ auth, instructions, logger, name, onToolCall, ping, prompts, resources, resourcesTemplates, roots, sessionId, stateless, tools, transportType, utils, version, }: {
|
|
730
795
|
auth?: T;
|
|
731
796
|
instructions?: string;
|
|
732
797
|
logger: Logger;
|
|
@@ -738,6 +803,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
|
|
|
738
803
|
resourcesTemplates: InputResourceTemplate<T>[];
|
|
739
804
|
roots?: ServerOptions<T>["roots"];
|
|
740
805
|
sessionId?: string;
|
|
806
|
+
stateless?: boolean;
|
|
741
807
|
tools: Tool<T>[];
|
|
742
808
|
transportType?: "httpStream" | "stdio";
|
|
743
809
|
utils?: ServerOptions<T>["utils"];
|
|
@@ -919,4 +985,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
919
985
|
stop(): Promise<void>;
|
|
920
986
|
}
|
|
921
987
|
|
|
922
|
-
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent };
|
|
988
|
+
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type JsonSchemaObject, type JsonSchemaStandardSchema, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent, jsonSchemaAdapter };
|
package/dist/FastMCP.d.ts
CHANGED
|
@@ -47,6 +47,71 @@ declare class DiscoveryDocumentCache {
|
|
|
47
47
|
has(url: string): boolean;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* A plain JSON Schema object descriptor.
|
|
52
|
+
*/
|
|
53
|
+
type JsonSchemaObject = {
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
$schema?: string;
|
|
56
|
+
additionalProperties?: boolean;
|
|
57
|
+
properties?: Record<string, unknown>;
|
|
58
|
+
required?: string[];
|
|
59
|
+
type: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A Standard Schema that also carries the JSON Schema it was built from.
|
|
63
|
+
*
|
|
64
|
+
* `~standard.jsonSchema` is the Standard JSON Schema extension. Anything that
|
|
65
|
+
* knows about it — including the `xsschema` conversion FastMCP uses to build
|
|
66
|
+
* `tools/list` — reads the schema straight off the object instead of trying to
|
|
67
|
+
* derive one from a validation library it does not recognise.
|
|
68
|
+
*/
|
|
69
|
+
interface JsonSchemaStandardSchema extends StandardSchemaV1 {
|
|
70
|
+
readonly "~standard": {
|
|
71
|
+
readonly jsonSchema: {
|
|
72
|
+
readonly input: () => JsonSchemaObject;
|
|
73
|
+
readonly output: () => JsonSchemaObject;
|
|
74
|
+
};
|
|
75
|
+
} & StandardSchemaV1.Props;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Wraps a plain JSON Schema object so it can be used as a tool's `parameters`
|
|
79
|
+
* or `outputSchema`, without pulling in Zod, Valibot, or another validation
|
|
80
|
+
* library.
|
|
81
|
+
*
|
|
82
|
+
* Validation uses AJV, which is an optional peer dependency — install `ajv`
|
|
83
|
+
* (and `ajv-formats` if you use `format` keywords) to use this. It is imported
|
|
84
|
+
* on first validation, so servers that never call this pay nothing for it.
|
|
85
|
+
*
|
|
86
|
+
* Note that FastMCP applies the same strictness to every tool schema: objects
|
|
87
|
+
* are advertised with `additionalProperties: false`, whatever the input schema
|
|
88
|
+
* said.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { FastMCP, jsonSchemaAdapter } from "fastmcp";
|
|
93
|
+
*
|
|
94
|
+
* const server = new FastMCP({ name: "Example", version: "1.0.0" });
|
|
95
|
+
*
|
|
96
|
+
* server.addTool({
|
|
97
|
+
* name: "greet",
|
|
98
|
+
* description: "Greet a user",
|
|
99
|
+
* parameters: jsonSchemaAdapter({
|
|
100
|
+
* type: "object",
|
|
101
|
+
* properties: {
|
|
102
|
+
* name: { type: "string" },
|
|
103
|
+
* },
|
|
104
|
+
* required: ["name"],
|
|
105
|
+
* }),
|
|
106
|
+
* execute: async ({ name }) => `Hello, ${name}!`,
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @param schema - A plain JSON Schema object
|
|
111
|
+
* @returns A Standard Schema that validates against `schema`
|
|
112
|
+
*/
|
|
113
|
+
declare function jsonSchemaAdapter(schema: JsonSchemaObject): JsonSchemaStandardSchema;
|
|
114
|
+
|
|
50
115
|
interface Logger {
|
|
51
116
|
debug(...args: unknown[]): void;
|
|
52
117
|
error(...args: unknown[]): void;
|
|
@@ -726,7 +791,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
|
|
|
726
791
|
get server(): Server;
|
|
727
792
|
get sessionId(): string | undefined;
|
|
728
793
|
set sessionId(value: string | undefined);
|
|
729
|
-
constructor({ auth, instructions, logger, name, onToolCall, ping, prompts, resources, resourcesTemplates, roots, sessionId, tools, transportType, utils, version, }: {
|
|
794
|
+
constructor({ auth, instructions, logger, name, onToolCall, ping, prompts, resources, resourcesTemplates, roots, sessionId, stateless, tools, transportType, utils, version, }: {
|
|
730
795
|
auth?: T;
|
|
731
796
|
instructions?: string;
|
|
732
797
|
logger: Logger;
|
|
@@ -738,6 +803,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
|
|
|
738
803
|
resourcesTemplates: InputResourceTemplate<T>[];
|
|
739
804
|
roots?: ServerOptions<T>["roots"];
|
|
740
805
|
sessionId?: string;
|
|
806
|
+
stateless?: boolean;
|
|
741
807
|
tools: Tool<T>[];
|
|
742
808
|
transportType?: "httpStream" | "stdio";
|
|
743
809
|
utils?: ServerOptions<T>["utils"];
|
|
@@ -919,4 +985,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
919
985
|
stop(): Promise<void>;
|
|
920
986
|
}
|
|
921
987
|
|
|
922
|
-
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent };
|
|
988
|
+
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type JsonSchemaObject, type JsonSchemaStandardSchema, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent, jsonSchemaAdapter };
|
package/dist/FastMCP.js
CHANGED
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
UnexpectedStateError,
|
|
7
7
|
UserError,
|
|
8
8
|
audioContent,
|
|
9
|
-
imageContent
|
|
10
|
-
|
|
9
|
+
imageContent,
|
|
10
|
+
jsonSchemaAdapter
|
|
11
|
+
} from "./chunk-MGP2FVUH.js";
|
|
11
12
|
import {
|
|
12
13
|
AuthProvider,
|
|
13
14
|
AzureProvider,
|
|
@@ -36,6 +37,7 @@ export {
|
|
|
36
37
|
audioContent,
|
|
37
38
|
getAuthSession,
|
|
38
39
|
imageContent,
|
|
40
|
+
jsonSchemaAdapter,
|
|
39
41
|
requireAll,
|
|
40
42
|
requireAny,
|
|
41
43
|
requireAuth,
|