mcp-use 1.6.2 → 1.7.0-canary.1
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/.tsbuildinfo +1 -1
- package/dist/chunk-JQKKMUCT.js +0 -0
- package/dist/chunk-PE7UMCVO.js +377 -0
- package/dist/{chunk-BWOTID2D.js → chunk-QSLJXXMG.js} +3 -346
- package/dist/chunk-R5DJJ4IV.js +942 -0
- package/dist/{chunk-SJEHVCPM.js → chunk-XN2PU4PS.js} +100 -23
- package/dist/index.cjs +132 -29
- package/dist/index.js +8 -5
- package/dist/oauth-CNGBFOZW.js +29 -0
- package/dist/src/agents/index.js +1 -1
- package/dist/src/auth/browser-provider.d.ts +2 -0
- package/dist/src/auth/browser-provider.d.ts.map +1 -1
- package/dist/src/auth/callback.d.ts.map +1 -1
- package/dist/src/auth/index.cjs +396 -0
- package/dist/src/auth/index.js +10 -0
- package/dist/src/auth/types.d.ts +3 -1
- package/dist/src/auth/types.d.ts.map +1 -1
- package/dist/src/browser.cjs +36 -8
- package/dist/src/browser.js +6 -4
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/react/index.cjs +132 -29
- package/dist/src/react/index.js +3 -2
- package/dist/src/react/types.d.ts +12 -1
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/server/context-storage.d.ts +54 -0
- package/dist/src/server/context-storage.d.ts.map +1 -0
- package/dist/src/server/index.cjs +1409 -410
- package/dist/src/server/index.d.ts +4 -1
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +420 -412
- package/dist/src/server/mcp-server.d.ts +50 -81
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/oauth/index.d.ts +13 -0
- package/dist/src/server/oauth/index.d.ts.map +1 -0
- package/dist/src/server/oauth/middleware.d.ts +19 -0
- package/dist/src/server/oauth/middleware.d.ts.map +1 -0
- package/dist/src/server/oauth/providers/auth0.d.ts +22 -0
- package/dist/src/server/oauth/providers/auth0.d.ts.map +1 -0
- package/dist/src/server/oauth/providers/custom.d.ts +19 -0
- package/dist/src/server/oauth/providers/custom.d.ts.map +1 -0
- package/dist/src/server/oauth/providers/keycloak.d.ts +22 -0
- package/dist/src/server/oauth/providers/keycloak.d.ts.map +1 -0
- package/dist/src/server/oauth/providers/supabase.d.ts +24 -0
- package/dist/src/server/oauth/providers/supabase.d.ts.map +1 -0
- package/dist/src/server/oauth/providers/types.d.ts +138 -0
- package/dist/src/server/oauth/providers/types.d.ts.map +1 -0
- package/dist/src/server/oauth/providers/workos.d.ts +30 -0
- package/dist/src/server/oauth/providers/workos.d.ts.map +1 -0
- package/dist/src/server/oauth/providers.d.ts +208 -0
- package/dist/src/server/oauth/providers.d.ts.map +1 -0
- package/dist/src/server/oauth/routes.d.ts +33 -0
- package/dist/src/server/oauth/routes.d.ts.map +1 -0
- package/dist/src/server/oauth/utils.d.ts +155 -0
- package/dist/src/server/oauth/utils.d.ts.map +1 -0
- package/dist/src/server/types/common.d.ts +47 -0
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/server/types/context.d.ts +34 -0
- package/dist/src/server/types/context.d.ts.map +1 -0
- package/dist/src/server/types/index.d.ts +2 -1
- package/dist/src/server/types/index.d.ts.map +1 -1
- package/dist/src/server/types/tool.d.ts +82 -9
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/dist/src/server/utils/index.d.ts +6 -0
- package/dist/src/server/utils/index.d.ts.map +1 -0
- package/dist/src/server/utils/response-helpers.d.ts +151 -0
- package/dist/src/server/utils/response-helpers.d.ts.map +1 -0
- package/dist/src/server/utils/runtime.d.ts +25 -0
- package/dist/src/server/utils/runtime.d.ts.map +1 -0
- package/dist/src/task_managers/streamable_http.d.ts +1 -0
- package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +14 -5
- /package/dist/{chunk-MCF5P6GJ.js → chunk-GVVPUU5K.js} +0 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth Provider Factory Functions
|
|
3
|
+
*
|
|
4
|
+
* Export factory functions for creating OAuth providers with better
|
|
5
|
+
* type safety and developer experience.
|
|
6
|
+
*/
|
|
7
|
+
import type { OAuthProvider } from "./providers/types.js";
|
|
8
|
+
import type { UserInfo } from "./providers/types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for Supabase OAuth provider
|
|
11
|
+
*/
|
|
12
|
+
export interface SupabaseProviderConfig {
|
|
13
|
+
projectId: string;
|
|
14
|
+
jwtSecret?: string;
|
|
15
|
+
skipVerification?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Configuration for Auth0 OAuth provider
|
|
19
|
+
*/
|
|
20
|
+
export interface Auth0ProviderConfig {
|
|
21
|
+
domain: string;
|
|
22
|
+
audience: string;
|
|
23
|
+
verifyJwt?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for Keycloak OAuth provider
|
|
27
|
+
*/
|
|
28
|
+
export interface KeycloakProviderConfig {
|
|
29
|
+
serverUrl: string;
|
|
30
|
+
realm: string;
|
|
31
|
+
clientId?: string;
|
|
32
|
+
verifyJwt?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for WorkOS OAuth provider
|
|
36
|
+
*/
|
|
37
|
+
export interface WorkOSProviderConfig {
|
|
38
|
+
subdomain: string;
|
|
39
|
+
clientId?: string;
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
verifyJwt?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for Custom OAuth provider
|
|
45
|
+
*/
|
|
46
|
+
export interface CustomProviderConfig {
|
|
47
|
+
issuer: string;
|
|
48
|
+
jwksUrl: string;
|
|
49
|
+
authEndpoint: string;
|
|
50
|
+
tokenEndpoint: string;
|
|
51
|
+
scopesSupported?: string[];
|
|
52
|
+
grantTypesSupported?: string[];
|
|
53
|
+
verifyToken: (token: string) => Promise<any>;
|
|
54
|
+
getUserInfo?: (payload: any) => UserInfo;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a Supabase OAuth provider
|
|
58
|
+
*
|
|
59
|
+
* Supports zero-config setup via environment variables:
|
|
60
|
+
* - MCP_USE_OAUTH_SUPABASE_PROJECT_ID (required)
|
|
61
|
+
* - MCP_USE_OAUTH_SUPABASE_JWT_SECRET (optional)
|
|
62
|
+
*
|
|
63
|
+
* @param config - Optional Supabase configuration (overrides environment variables)
|
|
64
|
+
* @returns OAuthProvider instance
|
|
65
|
+
*
|
|
66
|
+
* @example Zero-config with environment variables
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const server = createMCPServer('my-server', {
|
|
69
|
+
* oauth: oauthSupabaseProvider()
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example With explicit configuration
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const server = createMCPServer('my-server', {
|
|
76
|
+
* oauth: oauthSupabaseProvider({
|
|
77
|
+
* projectId: 'my-project',
|
|
78
|
+
* jwtSecret: process.env.SUPABASE_JWT_SECRET
|
|
79
|
+
* })
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function oauthSupabaseProvider(config?: Partial<SupabaseProviderConfig>): OAuthProvider;
|
|
84
|
+
/**
|
|
85
|
+
* Create an Auth0 OAuth provider
|
|
86
|
+
*
|
|
87
|
+
* Supports zero-config setup via environment variables:
|
|
88
|
+
* - MCP_USE_OAUTH_AUTH0_DOMAIN (required)
|
|
89
|
+
* - MCP_USE_OAUTH_AUTH0_AUDIENCE (required)
|
|
90
|
+
*
|
|
91
|
+
* @param config - Optional Auth0 configuration (overrides environment variables)
|
|
92
|
+
* @returns OAuthProvider instance
|
|
93
|
+
*
|
|
94
|
+
* @example Zero-config with environment variables
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const server = createMCPServer('my-server', {
|
|
97
|
+
* oauth: oauthAuth0Provider()
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @example With explicit configuration
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const server = createMCPServer('my-server', {
|
|
104
|
+
* oauth: oauthAuth0Provider({
|
|
105
|
+
* domain: 'my-tenant.auth0.com',
|
|
106
|
+
* audience: 'https://my-api.com'
|
|
107
|
+
* })
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function oauthAuth0Provider(config?: Partial<Auth0ProviderConfig>): OAuthProvider;
|
|
112
|
+
/**
|
|
113
|
+
* Create a Keycloak OAuth provider
|
|
114
|
+
*
|
|
115
|
+
* Supports zero-config setup via environment variables:
|
|
116
|
+
* - MCP_USE_OAUTH_KEYCLOAK_SERVER_URL (required)
|
|
117
|
+
* - MCP_USE_OAUTH_KEYCLOAK_REALM (required)
|
|
118
|
+
* - MCP_USE_OAUTH_KEYCLOAK_CLIENT_ID (optional)
|
|
119
|
+
*
|
|
120
|
+
* @param config - Optional Keycloak configuration (overrides environment variables)
|
|
121
|
+
* @returns OAuthProvider instance
|
|
122
|
+
*
|
|
123
|
+
* @example Zero-config with environment variables
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const server = createMCPServer('my-server', {
|
|
126
|
+
* oauth: oauthKeycloakProvider()
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example With explicit configuration
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const server = createMCPServer('my-server', {
|
|
133
|
+
* oauth: oauthKeycloakProvider({
|
|
134
|
+
* serverUrl: 'https://keycloak.example.com',
|
|
135
|
+
* realm: 'my-realm',
|
|
136
|
+
* clientId: 'my-client'
|
|
137
|
+
* })
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare function oauthKeycloakProvider(config?: Partial<KeycloakProviderConfig>): OAuthProvider;
|
|
142
|
+
/**
|
|
143
|
+
* Create a WorkOS OAuth provider
|
|
144
|
+
*
|
|
145
|
+
* Supports two OAuth modes:
|
|
146
|
+
*
|
|
147
|
+
* **1. Dynamic Client Registration (DCR)** - Recommended for MCP
|
|
148
|
+
* - Don't set MCP_USE_OAUTH_WORKOS_CLIENT_ID
|
|
149
|
+
* - MCP clients register themselves automatically with WorkOS
|
|
150
|
+
* - Enable DCR in WorkOS Dashboard under Connect → Configuration
|
|
151
|
+
*
|
|
152
|
+
* **2. Pre-registered OAuth Client** - For custom setups
|
|
153
|
+
* - Set MCP_USE_OAUTH_WORKOS_CLIENT_ID to your OAuth client ID from WorkOS Dashboard
|
|
154
|
+
* - Create the client in WorkOS Dashboard under Connect → OAuth Applications
|
|
155
|
+
* - Configure redirect URIs in the dashboard to match your MCP client
|
|
156
|
+
*
|
|
157
|
+
* Environment variables:
|
|
158
|
+
* - MCP_USE_OAUTH_WORKOS_SUBDOMAIN (required)
|
|
159
|
+
* - MCP_USE_OAUTH_WORKOS_CLIENT_ID (optional, for pre-registered client)
|
|
160
|
+
* - MCP_USE_OAUTH_WORKOS_API_KEY (optional, for WorkOS API calls)
|
|
161
|
+
*
|
|
162
|
+
* @param config - Optional WorkOS configuration (overrides environment variables)
|
|
163
|
+
* @returns OAuthProvider instance
|
|
164
|
+
*
|
|
165
|
+
* @example Dynamic Client Registration (recommended)
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const server = createMCPServer('my-server', {
|
|
168
|
+
* oauth: oauthWorkOSProvider({
|
|
169
|
+
* subdomain: 'my-company'
|
|
170
|
+
* })
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @example Pre-registered OAuth Client
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const server = createMCPServer('my-server', {
|
|
177
|
+
* oauth: oauthWorkOSProvider({
|
|
178
|
+
* subdomain: 'my-company',
|
|
179
|
+
* clientId: 'client_01KB5DRXBDDY1VGCBKY108SKJW'
|
|
180
|
+
* })
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export declare function oauthWorkOSProvider(config?: Partial<WorkOSProviderConfig>): OAuthProvider;
|
|
185
|
+
/**
|
|
186
|
+
* Create a custom OAuth provider
|
|
187
|
+
*
|
|
188
|
+
* @param config - Custom provider configuration
|
|
189
|
+
* @returns OAuthProvider instance
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* const server = createMCPServer('my-server', {
|
|
194
|
+
* oauth: oauthCustomProvider({
|
|
195
|
+
* issuer: 'https://oauth.example.com',
|
|
196
|
+
* jwksUrl: 'https://oauth.example.com/.well-known/jwks.json',
|
|
197
|
+
* authEndpoint: 'https://oauth.example.com/authorize',
|
|
198
|
+
* tokenEndpoint: 'https://oauth.example.com/token',
|
|
199
|
+
* verifyToken: async (token) => {
|
|
200
|
+
* // Custom verification logic
|
|
201
|
+
* return jwtVerify(token, ...);
|
|
202
|
+
* }
|
|
203
|
+
* })
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export declare function oauthCustomProvider(config: CustomProviderConfig): OAuthProvider;
|
|
208
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../../src/server/oauth/providers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAM1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGrD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAE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O,CAAC,sBAAsB,CAAM,GAC3C,aAAa,CA4Bf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,GAAE,OAAO,CAAC,oBAAoB,CAAM,GACzC,aAAa,CAwCf;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,oBAAoB,GAC3B,aAAa,CAKf"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth Routes
|
|
3
|
+
*
|
|
4
|
+
* Sets up OAuth 2.0 endpoints based on the provider's mode:
|
|
5
|
+
*
|
|
6
|
+
* **Direct Mode** (e.g., WorkOS):
|
|
7
|
+
* - Clients communicate directly with the OAuth provider
|
|
8
|
+
* - MCP server only provides metadata endpoints for discovery
|
|
9
|
+
* - No proxying of OAuth requests
|
|
10
|
+
*
|
|
11
|
+
* **Proxy Mode** (legacy):
|
|
12
|
+
* - MCP server proxies OAuth requests to the provider
|
|
13
|
+
* - Provides /authorize and /token endpoints
|
|
14
|
+
*/
|
|
15
|
+
import type { Hono } from "hono";
|
|
16
|
+
import type { OAuthProvider } from "./providers/types.js";
|
|
17
|
+
/**
|
|
18
|
+
* Setup OAuth routes on the Hono app
|
|
19
|
+
*
|
|
20
|
+
* In direct mode (e.g., WorkOS), creates:
|
|
21
|
+
* - GET /.well-known/oauth-authorization-server - Proxies provider's OAuth metadata
|
|
22
|
+
* - GET /.well-known/oauth-protected-resource - Protected resource metadata
|
|
23
|
+
*
|
|
24
|
+
* In proxy mode (legacy), also creates:
|
|
25
|
+
* - GET/POST /authorize - Authorization endpoint
|
|
26
|
+
* - POST /token - Token exchange endpoint
|
|
27
|
+
*
|
|
28
|
+
* @param app - The Hono application instance
|
|
29
|
+
* @param provider - The OAuth provider
|
|
30
|
+
* @param baseUrl - The base URL of this server (for metadata)
|
|
31
|
+
*/
|
|
32
|
+
export declare function setupOAuthRoutes(app: Hono, provider: OAuthProvider, baseUrl: string): void;
|
|
33
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/server/oauth/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,IAAI,EACT,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,MAAM,GACd,IAAI,CA4PN"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth Utility Helpers
|
|
3
|
+
*
|
|
4
|
+
* Provides convenience functions for scope/permission checking and
|
|
5
|
+
* accessing authentication information in tool callbacks and middleware.
|
|
6
|
+
*/
|
|
7
|
+
import type { Context, Next } from "hono";
|
|
8
|
+
/**
|
|
9
|
+
* Authentication information extracted from context
|
|
10
|
+
*/
|
|
11
|
+
export interface AuthInfo {
|
|
12
|
+
user: any;
|
|
13
|
+
payload: any;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
scopes: string[];
|
|
16
|
+
permissions: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get authentication info from context
|
|
20
|
+
*
|
|
21
|
+
* Works in both middleware and tool callbacks (via requestContext parameter).
|
|
22
|
+
*
|
|
23
|
+
* Note: With the new API, you can access auth directly via `requestContext.auth`
|
|
24
|
+
* This function is kept for backward compatibility.
|
|
25
|
+
*
|
|
26
|
+
* @param context - Hono context (from middleware or tool requestContext)
|
|
27
|
+
* @returns Authentication information
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // New way (preferred):
|
|
32
|
+
* server.tool({
|
|
33
|
+
* name: 'my-tool',
|
|
34
|
+
* cb: async (params, ctx, requestContext) => {
|
|
35
|
+
* const auth = requestContext.auth;
|
|
36
|
+
* console.log(auth.user.email);
|
|
37
|
+
* console.log(auth.scopes);
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Old way (still works):
|
|
42
|
+
* server.tool({
|
|
43
|
+
* name: 'my-tool',
|
|
44
|
+
* cb: async (params, ctx, req) => {
|
|
45
|
+
* const auth = getAuth(req);
|
|
46
|
+
* console.log(auth.user.email);
|
|
47
|
+
* }
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function getAuth(context: Context): AuthInfo;
|
|
52
|
+
/**
|
|
53
|
+
* Check if user has specific scope(s) or permission(s)
|
|
54
|
+
*
|
|
55
|
+
* Checks both OAuth scopes and permissions (Auth0 style).
|
|
56
|
+
* If multiple scopes are provided, ALL must be present.
|
|
57
|
+
* Use this inside tool callbacks to check scopes and return appropriate errors.
|
|
58
|
+
*
|
|
59
|
+
* @param context - Hono context (from tool requestContext parameter)
|
|
60
|
+
* @param needed - Single scope/permission or array of required scopes/permissions
|
|
61
|
+
* @returns true if user has all required scopes/permissions
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Check scope inside tool callback
|
|
66
|
+
* server.tool({
|
|
67
|
+
* name: 'delete-data',
|
|
68
|
+
* cb: async (params, ctx, requestContext) => {
|
|
69
|
+
* if (!hasScope(requestContext, 'delete:data')) {
|
|
70
|
+
* return {
|
|
71
|
+
* content: [{ type: 'text', text: 'Insufficient permissions' }],
|
|
72
|
+
* isError: true
|
|
73
|
+
* };
|
|
74
|
+
* }
|
|
75
|
+
* // ... tool implementation
|
|
76
|
+
* }
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Check multiple scopes
|
|
80
|
+
* if (hasScope(requestContext, ['read:data', 'write:data'])) {
|
|
81
|
+
* // User has both read:data AND write:data
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function hasScope(context: Context, needed: string | string[]): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Check if user has ANY of the provided scopes/permissions
|
|
88
|
+
*
|
|
89
|
+
* @param context - Hono context
|
|
90
|
+
* @param needed - Array of scopes/permissions (user needs at least one)
|
|
91
|
+
* @returns true if user has at least one of the required scopes/permissions
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* if (hasAnyScope(req, ['admin', 'moderator'])) {
|
|
96
|
+
* // User is either an admin OR moderator
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function hasAnyScope(context: Context, needed: string[]): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Create middleware that requires specific scope(s)/permission(s)
|
|
103
|
+
*
|
|
104
|
+
* Returns 403 Forbidden if user doesn't have the required scope(s).
|
|
105
|
+
* If multiple scopes are provided, ALL must be present.
|
|
106
|
+
* Note: For tool-level scope checking, use hasScope() inside the tool callback instead.
|
|
107
|
+
*
|
|
108
|
+
* @param needed - Single scope/permission or array of required scopes/permissions
|
|
109
|
+
* @returns Hono middleware function
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // Use on custom routes
|
|
114
|
+
* app.post('/admin/users', requireScope('admin'), async (c) => {
|
|
115
|
+
* // Only users with 'admin' scope can access
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* // Require multiple scopes on a route
|
|
119
|
+
* app.delete('/data/:id', requireScope(['admin', 'delete:data']), async (c) => {
|
|
120
|
+
* // User must have both scopes
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function requireScope(needed: string | string[]): (c: Context, next: Next) => Promise<(Response & import("hono").TypedResponse<{
|
|
125
|
+
error: string;
|
|
126
|
+
required: string[];
|
|
127
|
+
granted_scopes: string[];
|
|
128
|
+
granted_permissions: string[];
|
|
129
|
+
message: string;
|
|
130
|
+
}, 403, "json">) | undefined>;
|
|
131
|
+
/**
|
|
132
|
+
* Create middleware that requires ANY of the provided scopes/permissions
|
|
133
|
+
*
|
|
134
|
+
* Returns 403 Forbidden if user doesn't have at least one required scope.
|
|
135
|
+
* Note: For tool-level scope checking, use hasAnyScope() inside the tool callback instead.
|
|
136
|
+
*
|
|
137
|
+
* @param needed - Array of scopes/permissions (user needs at least one)
|
|
138
|
+
* @returns Hono middleware function
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // Use on custom routes - user needs to be either admin OR moderator
|
|
143
|
+
* app.post('/moderate', requireAnyScope(['admin', 'moderator']), async (c) => {
|
|
144
|
+
* // User has at least one of the required scopes
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function requireAnyScope(needed: string[]): (c: Context, next: Next) => Promise<(Response & import("hono").TypedResponse<{
|
|
149
|
+
error: string;
|
|
150
|
+
required_any: string[];
|
|
151
|
+
granted_scopes: string[];
|
|
152
|
+
granted_permissions: string[];
|
|
153
|
+
message: string;
|
|
154
|
+
}, 403, "json">) | undefined>;
|
|
155
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/server/oauth/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,CAElD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAQ7E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAOvE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,IACtC,GAAG,OAAO,EAAE,MAAM,IAAI;;;;;;8BAkBrC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAChC,GAAG,OAAO,EAAE,MAAM,IAAI;;;;;;8BAiBrC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Common type definitions shared across different MCP components
|
|
3
3
|
*/
|
|
4
|
+
import type { OAuthProvider } from "../oauth/providers/types.js";
|
|
4
5
|
export interface ServerConfig {
|
|
5
6
|
name: string;
|
|
6
7
|
version: string;
|
|
@@ -66,6 +67,52 @@ export interface ServerConfig {
|
|
|
66
67
|
* ```
|
|
67
68
|
*/
|
|
68
69
|
autoCreateSessionOnInvalidId?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* OAuth authentication configuration
|
|
72
|
+
*
|
|
73
|
+
* When provided, automatically sets up OAuth authentication for the server including:
|
|
74
|
+
* - OAuth routes (/authorize, /token, .well-known/*)
|
|
75
|
+
* - JWT verification middleware
|
|
76
|
+
* - Bearer token authentication on all /mcp routes
|
|
77
|
+
* - User information extraction and context attachment
|
|
78
|
+
*
|
|
79
|
+
* Use provider factory functions for type-safe configuration:
|
|
80
|
+
* - oauthSupabaseProvider() - Supabase OAuth
|
|
81
|
+
* - oauthAuth0Provider() - Auth0 OAuth
|
|
82
|
+
* - oauthKeycloakProvider() - Keycloak OAuth
|
|
83
|
+
* - oauthCustomProvider() - Custom OAuth implementation
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* import { createMCPServer, oauthSupabaseProvider } from 'mcp-use/server';
|
|
88
|
+
*
|
|
89
|
+
* // Supabase OAuth
|
|
90
|
+
* const server = createMCPServer('my-server', {
|
|
91
|
+
* oauth: oauthSupabaseProvider({
|
|
92
|
+
* projectId: 'my-project',
|
|
93
|
+
* jwtSecret: process.env.SUPABASE_JWT_SECRET
|
|
94
|
+
* })
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // Auth0 OAuth
|
|
98
|
+
* const server = createMCPServer('my-server', {
|
|
99
|
+
* oauth: oauthAuth0Provider({
|
|
100
|
+
* domain: 'my-tenant.auth0.com',
|
|
101
|
+
* audience: 'https://my-api.com'
|
|
102
|
+
* })
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* // Keycloak OAuth
|
|
106
|
+
* const server = createMCPServer('my-server', {
|
|
107
|
+
* oauth: oauthKeycloakProvider({
|
|
108
|
+
* serverUrl: 'https://keycloak.example.com',
|
|
109
|
+
* realm: 'my-realm',
|
|
110
|
+
* clientId: 'my-client'
|
|
111
|
+
* })
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
oauth?: OAuthProvider;
|
|
69
116
|
}
|
|
70
117
|
export interface InputDefinition {
|
|
71
118
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/server/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IAC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,GAAG,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC;IACpC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extended Hono Context types for MCP server
|
|
3
|
+
*/
|
|
4
|
+
import type { Context as HonoContext } from "hono";
|
|
5
|
+
import type { AuthInfo } from "../oauth/utils.js";
|
|
6
|
+
/**
|
|
7
|
+
* Base MCP Context without OAuth
|
|
8
|
+
*/
|
|
9
|
+
export interface McpContextBase extends HonoContext {
|
|
10
|
+
auth?: never;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* MCP Context with OAuth configured
|
|
14
|
+
*
|
|
15
|
+
* When OAuth is configured, the auth property is automatically populated
|
|
16
|
+
* by the OAuth middleware and guaranteed to be available in tool callbacks.
|
|
17
|
+
*/
|
|
18
|
+
export interface McpContextWithAuth extends HonoContext {
|
|
19
|
+
/**
|
|
20
|
+
* Authentication information from OAuth provider
|
|
21
|
+
*
|
|
22
|
+
* Includes user info, JWT payload, access token, scopes, and permissions.
|
|
23
|
+
* Always available when OAuth is configured since tools are protected by default.
|
|
24
|
+
*
|
|
25
|
+
* TypeScript knows this is always defined (non-undefined) when OAuth is configured.
|
|
26
|
+
*/
|
|
27
|
+
auth: AuthInfo;
|
|
28
|
+
readonly __hasOAuth?: true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Conditional MCP Context type based on OAuth configuration
|
|
32
|
+
*/
|
|
33
|
+
export type McpContext<HasOAuth extends boolean = false> = HasOAuth extends true ? McpContextWithAuth : McpContextBase;
|
|
34
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/server/types/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,IAAI,CAAC,EAAE,KAAK,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD;;;;;;;OAOG;IACH,IAAI,EAAE,QAAQ,CAAC;IAGf,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,QAAQ,SAAS,OAAO,GAAG,KAAK,IAAI,QAAQ,SAAS,IAAI,GAC5E,kBAAkB,GAClB,cAAc,CAAC"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Centralized type exports for MCP server
|
|
3
3
|
*/
|
|
4
4
|
export { ServerConfig, InputDefinition, ResourceAnnotations, } from "./common.js";
|
|
5
|
+
export { McpContext } from "./context.js";
|
|
5
6
|
export { ReadResourceCallback, ReadResourceTemplateCallback, ResourceTemplateConfig, ResourceTemplateDefinition, ResourceDefinition, UIResourceContent, WidgetProps, UIEncoding, RemoteDomFramework, UIResourceDefinition, ExternalUrlUIResource, RawHtmlUIResource, RemoteDomUIResource, AppsSdkUIResource, WidgetConfig, WidgetManifest, DiscoverWidgetsOptions, AppsSdkMetadata, AppsSdkToolMetadata, } from "./resource.js";
|
|
6
|
-
export { ToolCallback, ToolDefinition } from "./tool.js";
|
|
7
|
+
export { ToolCallback, ToolDefinition, InferToolInput, InferToolOutput, EnhancedToolContext, } from "./tool.js";
|
|
7
8
|
export { PromptCallback, PromptDefinition } from "./prompt.js";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,EACtB,0BAA0B,EAC1B,kBAAkB,EAElB,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,sBAAsB,EAEtB,eAAe,EACf,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAGvB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,EACtB,0BAA0B,EAC1B,kBAAkB,EAElB,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,sBAAsB,EAEtB,eAAe,EACf,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,eAAe,EACf,mBAAmB,GACpB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,28 +1,96 @@
|
|
|
1
|
-
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
1
|
import type { InputDefinition } from "./common.js";
|
|
3
2
|
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
4
3
|
import type { ToolContext } from "../mcp-server.js";
|
|
4
|
+
import type { McpContext } from "./context.js";
|
|
5
|
+
import type { z } from "zod";
|
|
6
|
+
import type { TypedCallToolResult } from "../utils/response-helpers.js";
|
|
7
|
+
/**
|
|
8
|
+
* Enhanced Tool Context that combines ToolContext methods with Hono request context.
|
|
9
|
+
*
|
|
10
|
+
* This unified context provides:
|
|
11
|
+
* - `sample()` - LLM sampling method from ToolContext
|
|
12
|
+
* - `reportProgress()` - Progress reporting from ToolContext
|
|
13
|
+
* - `auth` - Authentication info (when OAuth is configured)
|
|
14
|
+
* - `req` - Hono request object
|
|
15
|
+
* - All other Hono Context properties and methods
|
|
16
|
+
*
|
|
17
|
+
* @template HasOAuth - Whether OAuth is configured (affects auth availability)
|
|
18
|
+
*/
|
|
19
|
+
export type EnhancedToolContext<HasOAuth extends boolean = false> = ToolContext & McpContext<HasOAuth>;
|
|
5
20
|
/**
|
|
6
21
|
* Callback function for tool execution.
|
|
7
|
-
*
|
|
22
|
+
*
|
|
23
|
+
* Accepts input parameters and an enhanced context object that provides:
|
|
24
|
+
* - LLM sampling via `ctx.sample()`
|
|
25
|
+
* - Progress reporting via `ctx.reportProgress()`
|
|
26
|
+
* - Authentication info via `ctx.auth` (when OAuth is configured)
|
|
27
|
+
* - HTTP request via `ctx.req`
|
|
28
|
+
* - All Hono Context properties and methods
|
|
29
|
+
*
|
|
30
|
+
* @template TInput - Input parameters type
|
|
31
|
+
* @template TOutput - Output type (constrains the structuredContent property when outputSchema is defined)
|
|
32
|
+
* @template HasOAuth - Whether OAuth is configured (affects ctx.auth availability)
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Simple tool without context
|
|
37
|
+
* cb: async ({ name }) => ({
|
|
38
|
+
* content: [{ type: 'text', text: `Hello, ${name}!` }]
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* // Tool with sampling
|
|
42
|
+
* cb: async ({ text }, ctx) => {
|
|
43
|
+
* const result = await ctx.sample({
|
|
44
|
+
* messages: [{ role: 'user', content: { type: 'text', text } }]
|
|
45
|
+
* });
|
|
46
|
+
* return { content: result.content };
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* // Tool with authentication
|
|
50
|
+
* cb: async ({ userId }, ctx) => {
|
|
51
|
+
* return { content: [{ type: 'text', text: `User: ${ctx.auth.user.email}` }] };
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export type ToolCallback<TInput = Record<string, any>, TOutput extends Record<string, unknown> = Record<string, unknown>, HasOAuth extends boolean = false> = ((params: TInput) => Promise<TypedCallToolResult<TOutput>>) | ((params: TInput, ctx: EnhancedToolContext<HasOAuth>) => Promise<TypedCallToolResult<TOutput>>);
|
|
56
|
+
/**
|
|
57
|
+
* Generic callback with full context support for better type inference.
|
|
58
|
+
* This variant always requires the context parameter.
|
|
59
|
+
*/
|
|
60
|
+
export type ToolCallbackWithContext<TInput = Record<string, any>, TOutput extends Record<string, unknown> = Record<string, unknown>, HasOAuth extends boolean = false> = (params: TInput, ctx: EnhancedToolContext<HasOAuth>) => Promise<TypedCallToolResult<TOutput>>;
|
|
61
|
+
/**
|
|
62
|
+
* Extract input type from a tool definition's schema
|
|
63
|
+
*/
|
|
64
|
+
export type InferToolInput<T> = T extends {
|
|
65
|
+
schema: infer S;
|
|
66
|
+
} ? S extends z.ZodTypeAny ? z.infer<S> : Record<string, any> : Record<string, any>;
|
|
67
|
+
/**
|
|
68
|
+
* Extract output type from a tool definition's output schema
|
|
8
69
|
*/
|
|
9
|
-
export type
|
|
10
|
-
|
|
70
|
+
export type InferToolOutput<T> = T extends {
|
|
71
|
+
outputSchema: infer S;
|
|
72
|
+
} ? S extends z.ZodTypeAny ? z.infer<S> : Record<string, unknown> : Record<string, unknown>;
|
|
73
|
+
export interface ToolDefinition<TInput = Record<string, any>, TOutput extends Record<string, unknown> = Record<string, unknown>, HasOAuth extends boolean = false> {
|
|
11
74
|
/** Unique identifier for the tool */
|
|
12
75
|
name: string;
|
|
13
76
|
/** Human-readable title for the tool (displayed in UI) */
|
|
14
77
|
title?: string;
|
|
15
|
-
/** Description of what the tool does */
|
|
78
|
+
/** Description of what the tool does (optional) */
|
|
16
79
|
description?: string;
|
|
17
|
-
/** Input parameter definitions */
|
|
80
|
+
/** Input parameter definitions (legacy, use schema instead) */
|
|
81
|
+
/** @deprecated Use schema instead */
|
|
18
82
|
inputs?: InputDefinition[];
|
|
83
|
+
/** Zod schema for input validation (alias for inputs, preferred) */
|
|
84
|
+
schema?: z.ZodObject<any>;
|
|
85
|
+
/** Zod schema for structured output validation */
|
|
86
|
+
outputSchema?: z.ZodObject<any>;
|
|
19
87
|
/**
|
|
20
88
|
* Async callback function that executes the tool.
|
|
21
|
-
* Receives tool parameters and
|
|
89
|
+
* Receives tool parameters and an enhanced context with sampling, auth, and request info.
|
|
22
90
|
*
|
|
23
91
|
* @example
|
|
24
92
|
* ```typescript
|
|
25
|
-
* // Simple tool without
|
|
93
|
+
* // Simple tool without context
|
|
26
94
|
* cb: async ({ name }) => ({
|
|
27
95
|
* content: [{ type: 'text', text: `Hello, ${name}!` }]
|
|
28
96
|
* })
|
|
@@ -34,9 +102,14 @@ export interface ToolDefinition {
|
|
|
34
102
|
* });
|
|
35
103
|
* return { content: result.content };
|
|
36
104
|
* }
|
|
105
|
+
*
|
|
106
|
+
* // Tool with authentication
|
|
107
|
+
* cb: async ({ userId }, ctx) => {
|
|
108
|
+
* return { content: [{ type: 'text', text: `User: ${ctx.auth.user.email}` }] };
|
|
109
|
+
* }
|
|
37
110
|
* ```
|
|
38
111
|
*/
|
|
39
|
-
cb
|
|
112
|
+
cb?: ToolCallback<TInput, TOutput, HasOAuth>;
|
|
40
113
|
/** Tool annotations */
|
|
41
114
|
annotations?: ToolAnnotations;
|
|
42
115
|
/** Metadata for the tool */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../../src/server/types/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../../src/server/types/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,CAAC,QAAQ,SAAS,OAAO,GAAG,KAAK,IAC9D,WAAW,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,YAAY,CACtB,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,QAAQ,SAAS,OAAO,GAAG,KAAK,IAE9B,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,GAC3D,CAAC,CACC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,mBAAmB,CAAC,QAAQ,CAAC,KAC/B,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhD;;;GAGG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