@ai-sdk/mcp 1.0.83 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/mcp",
3
- "version": "1.0.83",
3
+ "version": "1.0.85",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -34,8 +34,8 @@
34
34
  "dependencies": {
35
35
  "cross-spawn": "^7.0.6",
36
36
  "pkce-challenge": "^5.0.0",
37
- "@ai-sdk/provider": "3.0.16",
38
- "@ai-sdk/provider-utils": "4.0.52"
37
+ "@ai-sdk/provider": "3.0.17",
38
+ "@ai-sdk/provider-utils": "4.0.54"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/cross-spawn": "^6.0.6",
@@ -44,8 +44,8 @@
44
44
  "typescript": "5.8.3",
45
45
  "vitest": "^4.1.0",
46
46
  "zod": "3.25.76",
47
- "@vercel/ai-tsconfig": "0.0.0",
48
- "@ai-sdk/test-server": "1.0.6"
47
+ "@ai-sdk/test-server": "1.0.6",
48
+ "@vercel/ai-tsconfig": "0.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "zod": "^3.25.76 || ^4.1.8"
@@ -757,24 +757,20 @@ class DefaultMCPClient implements MCPClient {
757
757
  args: Record<string, unknown>;
758
758
  options?: ToolExecutionOptions;
759
759
  }): Promise<CallToolResult> {
760
- try {
761
- return this.callToolWithRetry({
762
- options,
763
- execute: () =>
764
- this.request({
765
- request: {
766
- method: 'tools/call',
767
- params: { name, arguments: args },
768
- },
769
- resultSchema: CallToolResultSchema,
770
- options: {
771
- signal: options?.abortSignal,
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
- try {
788
- return this.request({
789
- request: { method: 'resources/list', params },
790
- resultSchema: ListResourcesResultSchema,
791
- options,
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
- try {
806
- return this.request({
807
- request: { method: 'resources/read', params: { uri } },
808
- resultSchema: ReadResourceResultSchema,
809
- options,
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
- try {
822
- return this.request({
823
- request: { method: 'resources/templates/list' },
824
- resultSchema: ListResourceTemplatesResultSchema,
825
- options,
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
- try {
840
- return this.request({
841
- request: { method: 'prompts/list', params },
842
- resultSchema: ListPromptsResultSchema,
843
- options,
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
- try {
860
- return this.request({
861
- request: { method: 'prompts/get', params: { name, arguments: args } },
862
- resultSchema: GetPromptResultSchema,
863
- options,
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) {