@ai-sdk/mcp 1.0.84 → 1.0.85
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/CHANGELOG.md +11 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +44 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -65
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/tool/mcp-client.ts +39 -63
- package/src/tool/oauth.ts +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.85",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"cross-spawn": "^7.0.6",
|
|
36
36
|
"pkce-challenge": "^5.0.0",
|
|
37
37
|
"@ai-sdk/provider": "3.0.17",
|
|
38
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
38
|
+
"@ai-sdk/provider-utils": "4.0.54"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/cross-spawn": "^6.0.6",
|
package/src/tool/mcp-client.ts
CHANGED
|
@@ -757,24 +757,20 @@ class DefaultMCPClient implements MCPClient {
|
|
|
757
757
|
args: Record<string, unknown>;
|
|
758
758
|
options?: ToolExecutionOptions;
|
|
759
759
|
}): Promise<CallToolResult> {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
});
|
|
775
|
-
} catch (error) {
|
|
776
|
-
throw error;
|
|
777
|
-
}
|
|
760
|
+
return this.callToolWithRetry({
|
|
761
|
+
options,
|
|
762
|
+
execute: () =>
|
|
763
|
+
this.request({
|
|
764
|
+
request: {
|
|
765
|
+
method: 'tools/call',
|
|
766
|
+
params: { name, arguments: args },
|
|
767
|
+
},
|
|
768
|
+
resultSchema: CallToolResultSchema,
|
|
769
|
+
options: {
|
|
770
|
+
signal: options?.abortSignal,
|
|
771
|
+
},
|
|
772
|
+
}),
|
|
773
|
+
});
|
|
778
774
|
}
|
|
779
775
|
|
|
780
776
|
private async listResourcesInternal({
|
|
@@ -784,15 +780,11 @@ class DefaultMCPClient implements MCPClient {
|
|
|
784
780
|
params?: PaginatedRequest['params'];
|
|
785
781
|
options?: RequestOptions;
|
|
786
782
|
} = {}): Promise<ListResourcesResult> {
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
});
|
|
793
|
-
} catch (error) {
|
|
794
|
-
throw error;
|
|
795
|
-
}
|
|
783
|
+
return this.request({
|
|
784
|
+
request: { method: 'resources/list', params },
|
|
785
|
+
resultSchema: ListResourcesResultSchema,
|
|
786
|
+
options,
|
|
787
|
+
});
|
|
796
788
|
}
|
|
797
789
|
|
|
798
790
|
private async readResourceInternal({
|
|
@@ -802,15 +794,11 @@ class DefaultMCPClient implements MCPClient {
|
|
|
802
794
|
uri: string;
|
|
803
795
|
options?: RequestOptions;
|
|
804
796
|
}): Promise<ReadResourceResult> {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
});
|
|
811
|
-
} catch (error) {
|
|
812
|
-
throw error;
|
|
813
|
-
}
|
|
797
|
+
return this.request({
|
|
798
|
+
request: { method: 'resources/read', params: { uri } },
|
|
799
|
+
resultSchema: ReadResourceResultSchema,
|
|
800
|
+
options,
|
|
801
|
+
});
|
|
814
802
|
}
|
|
815
803
|
|
|
816
804
|
private async listResourceTemplatesInternal({
|
|
@@ -818,15 +806,11 @@ class DefaultMCPClient implements MCPClient {
|
|
|
818
806
|
}: {
|
|
819
807
|
options?: RequestOptions;
|
|
820
808
|
} = {}): Promise<ListResourceTemplatesResult> {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
});
|
|
827
|
-
} catch (error) {
|
|
828
|
-
throw error;
|
|
829
|
-
}
|
|
809
|
+
return this.request({
|
|
810
|
+
request: { method: 'resources/templates/list' },
|
|
811
|
+
resultSchema: ListResourceTemplatesResultSchema,
|
|
812
|
+
options,
|
|
813
|
+
});
|
|
830
814
|
}
|
|
831
815
|
|
|
832
816
|
private async listPromptsInternal({
|
|
@@ -836,15 +820,11 @@ class DefaultMCPClient implements MCPClient {
|
|
|
836
820
|
params?: PaginatedRequest['params'];
|
|
837
821
|
options?: RequestOptions;
|
|
838
822
|
} = {}): Promise<ListPromptsResult> {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
});
|
|
845
|
-
} catch (error) {
|
|
846
|
-
throw error;
|
|
847
|
-
}
|
|
823
|
+
return this.request({
|
|
824
|
+
request: { method: 'prompts/list', params },
|
|
825
|
+
resultSchema: ListPromptsResultSchema,
|
|
826
|
+
options,
|
|
827
|
+
});
|
|
848
828
|
}
|
|
849
829
|
|
|
850
830
|
private async getPromptInternal({
|
|
@@ -856,15 +836,11 @@ class DefaultMCPClient implements MCPClient {
|
|
|
856
836
|
args?: Record<string, unknown>;
|
|
857
837
|
options?: RequestOptions;
|
|
858
838
|
}): Promise<GetPromptResult> {
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
});
|
|
865
|
-
} catch (error) {
|
|
866
|
-
throw error;
|
|
867
|
-
}
|
|
839
|
+
return this.request({
|
|
840
|
+
request: { method: 'prompts/get', params: { name, arguments: args } },
|
|
841
|
+
resultSchema: GetPromptResultSchema,
|
|
842
|
+
options,
|
|
843
|
+
});
|
|
868
844
|
}
|
|
869
845
|
|
|
870
846
|
private async completeInternal({
|
package/src/tool/oauth.ts
CHANGED
|
@@ -88,6 +88,16 @@ export interface OAuthClientProvider {
|
|
|
88
88
|
| OAuthClientInformation
|
|
89
89
|
| undefined
|
|
90
90
|
| Promise<OAuthClientInformation | undefined>;
|
|
91
|
+
/**
|
|
92
|
+
* Returns whether the current client information was obtained through
|
|
93
|
+
* dynamic client registration.
|
|
94
|
+
*
|
|
95
|
+
* Return `true` only when the current client information was saved after a
|
|
96
|
+
* dynamic registration response. When this method is omitted or returns
|
|
97
|
+
* `false`, the client information is treated as pre-registered and is not
|
|
98
|
+
* automatically invalidated after client authentication errors.
|
|
99
|
+
*/
|
|
100
|
+
isClientInformationDynamicallyRegistered?(): boolean | Promise<boolean>;
|
|
91
101
|
saveClientInformation?(
|
|
92
102
|
clientInformation: OAuthClientInformation,
|
|
93
103
|
): void | Promise<void>;
|
|
@@ -1137,6 +1147,13 @@ export async function auth(
|
|
|
1137
1147
|
error instanceof InvalidClientError ||
|
|
1138
1148
|
error instanceof UnauthorizedClientError
|
|
1139
1149
|
) {
|
|
1150
|
+
if (
|
|
1151
|
+
options.authorizationCode !== undefined ||
|
|
1152
|
+
!(await provider.isClientInformationDynamicallyRegistered?.())
|
|
1153
|
+
) {
|
|
1154
|
+
throw error;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1140
1157
|
await provider.invalidateCredentials?.('all');
|
|
1141
1158
|
return await authInternal(provider, options);
|
|
1142
1159
|
} else if (error instanceof InvalidGrantError) {
|