tmcp 1.19.0 → 1.19.2
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 +26 -0
- package/package.json +1 -1
- package/src/index.js +78 -200
- package/src/internal/internal.d.ts +11 -28
- package/src/resource.js +1 -1
- package/src/template.js +1 -1
- package/src/types/index.d.ts +8 -4
- package/src/types/index.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -1484,6 +1484,32 @@ Common scenarios where `enabled` functions are useful:
|
|
|
1484
1484
|
5. **Time-based access**: Enable tools only during specific hours
|
|
1485
1485
|
6. **License restrictions**: Limit features based on subscription level
|
|
1486
1486
|
|
|
1487
|
+
## Dynamic Properties with Getters
|
|
1488
|
+
|
|
1489
|
+
Sometimes you need properties that are computed dynamically at list-time rather than registration-time. For example, you might want to serve different descriptions based on which client is connected.
|
|
1490
|
+
|
|
1491
|
+
`tmcp` preserves JavaScript getters on the configuration object, allowing you to define properties that are evaluated each time the capability is listed:
|
|
1492
|
+
|
|
1493
|
+
```javascript
|
|
1494
|
+
server.tool(
|
|
1495
|
+
{
|
|
1496
|
+
name: 'search',
|
|
1497
|
+
get description() {
|
|
1498
|
+
const client = server.ctx.sessionInfo?.clientInfo?.name;
|
|
1499
|
+
if (client === 'claude-code') {
|
|
1500
|
+
return 'Search the codebase for files, symbols, or text patterns';
|
|
1501
|
+
}
|
|
1502
|
+
return 'Search for information';
|
|
1503
|
+
},
|
|
1504
|
+
},
|
|
1505
|
+
() => {
|
|
1506
|
+
return { content: [{ type: 'text', text: 'Search results...' }] };
|
|
1507
|
+
},
|
|
1508
|
+
);
|
|
1509
|
+
```
|
|
1510
|
+
|
|
1511
|
+
The same pattern works for resources, templates, and prompts.
|
|
1512
|
+
|
|
1487
1513
|
## Contributing
|
|
1488
1514
|
|
|
1489
1515
|
Contributions are welcome! Please see our [contributing guidelines](../../CONTRIBUTING.md) for details.
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -666,10 +666,7 @@ export class McpServer {
|
|
|
666
666
|
const all_resources = [];
|
|
667
667
|
|
|
668
668
|
// Add static resources
|
|
669
|
-
for (const [
|
|
670
|
-
uri,
|
|
671
|
-
{ description, name, title, icons, ...resource },
|
|
672
|
-
] of this.#resources) {
|
|
669
|
+
for (const [uri, resource] of this.#resources) {
|
|
673
670
|
if (!resource.template) {
|
|
674
671
|
if (
|
|
675
672
|
resource.enabled != null &&
|
|
@@ -677,11 +674,12 @@ export class McpServer {
|
|
|
677
674
|
)
|
|
678
675
|
continue;
|
|
679
676
|
all_resources.push({
|
|
680
|
-
name,
|
|
681
|
-
title: title || description,
|
|
682
|
-
description,
|
|
677
|
+
name: resource.name,
|
|
678
|
+
title: resource.title || resource.description,
|
|
679
|
+
description: resource.description,
|
|
683
680
|
uri,
|
|
684
|
-
|
|
681
|
+
mimeType: resource.mimeType,
|
|
682
|
+
icons: resource.icons,
|
|
685
683
|
});
|
|
686
684
|
} else if (resource.list_resources) {
|
|
687
685
|
if (
|
|
@@ -719,33 +717,22 @@ export class McpServer {
|
|
|
719
717
|
return {
|
|
720
718
|
resourceTemplates: (
|
|
721
719
|
await Promise.all(
|
|
722
|
-
[...this.#resources].map(
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
)
|
|
739
|
-
return null;
|
|
740
|
-
return {
|
|
741
|
-
name,
|
|
742
|
-
icons,
|
|
743
|
-
title: title || description,
|
|
744
|
-
description,
|
|
745
|
-
uriTemplate: uri,
|
|
746
|
-
};
|
|
747
|
-
},
|
|
748
|
-
),
|
|
720
|
+
[...this.#resources].map(async ([uri, resource]) => {
|
|
721
|
+
if (!resource.template) return null;
|
|
722
|
+
if (
|
|
723
|
+
resource.enabled != null &&
|
|
724
|
+
(await safe_enabled(resource.enabled)) === false
|
|
725
|
+
)
|
|
726
|
+
return null;
|
|
727
|
+
return {
|
|
728
|
+
name: resource.name,
|
|
729
|
+
icons: resource.icons,
|
|
730
|
+
title: resource.title || resource.description,
|
|
731
|
+
description: resource.description,
|
|
732
|
+
mimeType: resource.mimeType,
|
|
733
|
+
uriTemplate: uri,
|
|
734
|
+
};
|
|
735
|
+
}),
|
|
749
736
|
)
|
|
750
737
|
).filter((resource) => resource != null),
|
|
751
738
|
};
|
|
@@ -869,22 +856,7 @@ export class McpServer {
|
|
|
869
856
|
*/
|
|
870
857
|
tools(tools) {
|
|
871
858
|
for (const tool of tools) {
|
|
872
|
-
this.tool(
|
|
873
|
-
{
|
|
874
|
-
name: tool.name,
|
|
875
|
-
description: tool.description,
|
|
876
|
-
title: tool.title,
|
|
877
|
-
schema: tool.schema,
|
|
878
|
-
outputSchema: tool.outputSchema,
|
|
879
|
-
annotations: tool.annotations,
|
|
880
|
-
enabled: tool.enabled,
|
|
881
|
-
icons: tool.icons,
|
|
882
|
-
_meta: tool._meta,
|
|
883
|
-
},
|
|
884
|
-
// @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
|
|
885
|
-
// from showing in intellisense when declaring a tool inline
|
|
886
|
-
tool.execute,
|
|
887
|
-
);
|
|
859
|
+
this.tool(tool);
|
|
888
860
|
}
|
|
889
861
|
}
|
|
890
862
|
|
|
@@ -896,20 +868,7 @@ export class McpServer {
|
|
|
896
868
|
*/
|
|
897
869
|
prompts(prompts) {
|
|
898
870
|
for (const prompt of prompts) {
|
|
899
|
-
this.prompt(
|
|
900
|
-
{
|
|
901
|
-
name: prompt.name,
|
|
902
|
-
description: prompt.description,
|
|
903
|
-
title: prompt.title,
|
|
904
|
-
schema: prompt.schema,
|
|
905
|
-
complete: prompt.complete,
|
|
906
|
-
enabled: prompt.enabled,
|
|
907
|
-
icons: prompt.icons,
|
|
908
|
-
},
|
|
909
|
-
// @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
|
|
910
|
-
// from showing in intellisense when declaring a tool inline
|
|
911
|
-
prompt.execute,
|
|
912
|
-
);
|
|
871
|
+
this.prompt(prompt);
|
|
913
872
|
}
|
|
914
873
|
}
|
|
915
874
|
|
|
@@ -920,19 +879,7 @@ export class McpServer {
|
|
|
920
879
|
*/
|
|
921
880
|
resources(resources) {
|
|
922
881
|
for (const resource of resources) {
|
|
923
|
-
this.resource(
|
|
924
|
-
{
|
|
925
|
-
name: resource.name,
|
|
926
|
-
description: resource.description,
|
|
927
|
-
title: resource.title,
|
|
928
|
-
uri: resource.uri,
|
|
929
|
-
enabled: resource.enabled,
|
|
930
|
-
icons: resource.icons,
|
|
931
|
-
},
|
|
932
|
-
// @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
|
|
933
|
-
// from showing in intellisense when declaring a tool inline
|
|
934
|
-
resource.execute,
|
|
935
|
-
);
|
|
882
|
+
this.resource(resource);
|
|
936
883
|
}
|
|
937
884
|
}
|
|
938
885
|
|
|
@@ -943,21 +890,7 @@ export class McpServer {
|
|
|
943
890
|
*/
|
|
944
891
|
templates(templates) {
|
|
945
892
|
for (const template of templates) {
|
|
946
|
-
this.template(
|
|
947
|
-
{
|
|
948
|
-
name: template.name,
|
|
949
|
-
description: template.description,
|
|
950
|
-
title: template.title,
|
|
951
|
-
uri: template.uri,
|
|
952
|
-
complete: template.complete,
|
|
953
|
-
list: template.list,
|
|
954
|
-
enabled: template.enabled,
|
|
955
|
-
icons: template.icons,
|
|
956
|
-
},
|
|
957
|
-
// @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
|
|
958
|
-
// from showing in intellisense when declaring a tool inline
|
|
959
|
-
template.execute,
|
|
960
|
-
);
|
|
893
|
+
this.template(template);
|
|
961
894
|
}
|
|
962
895
|
}
|
|
963
896
|
|
|
@@ -994,38 +927,18 @@ export class McpServer {
|
|
|
994
927
|
* @param {CreatedTool<TSchema, TOutputSchema> | ToolOptions<TSchema, TOutputSchema>} tool_or_options
|
|
995
928
|
* @param {undefined | TSchema extends undefined ? (()=>Promise<CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>) : ((input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>)} [execute]
|
|
996
929
|
*/
|
|
997
|
-
tool(
|
|
998
|
-
{
|
|
999
|
-
name,
|
|
1000
|
-
description,
|
|
1001
|
-
title,
|
|
1002
|
-
schema,
|
|
1003
|
-
outputSchema,
|
|
1004
|
-
annotations,
|
|
1005
|
-
enabled,
|
|
1006
|
-
icons,
|
|
1007
|
-
_meta,
|
|
1008
|
-
...tool_or_options
|
|
1009
|
-
},
|
|
1010
|
-
execute,
|
|
1011
|
-
) {
|
|
930
|
+
tool(tool_or_options, execute) {
|
|
1012
931
|
if ('execute' in tool_or_options) {
|
|
1013
932
|
// @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
|
|
1014
933
|
// from showing in intellisense when declaring a tool inline
|
|
1015
934
|
execute = tool_or_options.execute;
|
|
1016
935
|
}
|
|
1017
936
|
this.#notify_tools_list_changed();
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
outputSchema,
|
|
1024
|
-
execute: /** @type {NonNullable<typeof execute>} */ (execute),
|
|
1025
|
-
annotations,
|
|
1026
|
-
icons,
|
|
1027
|
-
_meta,
|
|
1028
|
-
});
|
|
937
|
+
const stored_tool = /** @type {Tool<any, any>} */ (tool_or_options);
|
|
938
|
+
stored_tool.execute = /** @type {NonNullable<typeof execute>} */ (
|
|
939
|
+
execute
|
|
940
|
+
);
|
|
941
|
+
this.#tools.set(tool_or_options.name, stored_tool);
|
|
1029
942
|
}
|
|
1030
943
|
|
|
1031
944
|
/**
|
|
@@ -1058,52 +971,43 @@ export class McpServer {
|
|
|
1058
971
|
* A prompt can also have a schema that defines the input it expects, the user will be prompted to enter the inputs you request. It can also have a complete function
|
|
1059
972
|
* for each input that will be used to provide completions for the user.
|
|
1060
973
|
* @template {StandardSchema | undefined} [TSchema=undefined]
|
|
1061
|
-
* @param {CreatedPrompt<TSchema> | PromptOptions<TSchema>}
|
|
974
|
+
* @param {CreatedPrompt<TSchema> | PromptOptions<TSchema>} prompt_or_options
|
|
1062
975
|
* @param {TSchema extends undefined ? (()=>Promise<GetPromptResult> | GetPromptResult) : (input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<GetPromptResult> | GetPromptResult} [execute]
|
|
1063
976
|
*/
|
|
1064
|
-
prompt(
|
|
1065
|
-
{
|
|
1066
|
-
name,
|
|
1067
|
-
description,
|
|
1068
|
-
title,
|
|
1069
|
-
schema,
|
|
1070
|
-
complete,
|
|
1071
|
-
enabled,
|
|
1072
|
-
icons,
|
|
1073
|
-
...prompt_or_options
|
|
1074
|
-
},
|
|
1075
|
-
execute,
|
|
1076
|
-
) {
|
|
977
|
+
prompt(prompt_or_options, execute) {
|
|
1077
978
|
if ('execute' in prompt_or_options) {
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
979
|
+
execute = /** @type {NonNullable<typeof execute>} */ (
|
|
980
|
+
prompt_or_options.execute
|
|
981
|
+
);
|
|
1081
982
|
}
|
|
1082
|
-
if (complete) {
|
|
1083
|
-
this.#completions['ref/prompt'].set(
|
|
983
|
+
if (prompt_or_options.complete) {
|
|
984
|
+
this.#completions['ref/prompt'].set(
|
|
985
|
+
prompt_or_options.name,
|
|
986
|
+
prompt_or_options.complete,
|
|
987
|
+
);
|
|
1084
988
|
}
|
|
1085
989
|
this.#notify_prompts_list_changed();
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
enabled,
|
|
1092
|
-
icons,
|
|
1093
|
-
});
|
|
990
|
+
const stored_prompt = /** @type {Prompt<any>} */ (prompt_or_options);
|
|
991
|
+
stored_prompt.execute = /** @type {NonNullable<typeof execute>} */ (
|
|
992
|
+
execute
|
|
993
|
+
);
|
|
994
|
+
this.#prompts.set(prompt_or_options.name, stored_prompt);
|
|
1094
995
|
}
|
|
1095
996
|
/**
|
|
1096
|
-
* @type {(resource: StoredResource & {
|
|
997
|
+
* @type {(resource: StoredResource & { uri: string })=> void}
|
|
1097
998
|
*/
|
|
1098
|
-
#resource(
|
|
1099
|
-
if (complete) {
|
|
1100
|
-
this.#completions['ref/resource'].set(
|
|
999
|
+
#resource(resource) {
|
|
1000
|
+
if (resource.template && resource.complete) {
|
|
1001
|
+
this.#completions['ref/resource'].set(
|
|
1002
|
+
resource.uri,
|
|
1003
|
+
resource.complete,
|
|
1004
|
+
);
|
|
1101
1005
|
}
|
|
1102
1006
|
if (resource.template) {
|
|
1103
|
-
this.#templates.add(uri);
|
|
1007
|
+
this.#templates.add(resource.uri);
|
|
1104
1008
|
}
|
|
1105
1009
|
this.#notify_resources_list_changed();
|
|
1106
|
-
this.#resources.set(uri, resource);
|
|
1010
|
+
this.#resources.set(resource.uri, resource);
|
|
1107
1011
|
}
|
|
1108
1012
|
|
|
1109
1013
|
/**
|
|
@@ -1127,33 +1031,21 @@ export class McpServer {
|
|
|
1127
1031
|
* @param {CreatedResource | ResourceOptions} resource_or_options
|
|
1128
1032
|
* @param {(uri: string) => Promise<ReadResourceResult> | ReadResourceResult} [execute]
|
|
1129
1033
|
*/
|
|
1130
|
-
resource(
|
|
1131
|
-
{
|
|
1132
|
-
name,
|
|
1133
|
-
description,
|
|
1134
|
-
title,
|
|
1135
|
-
uri,
|
|
1136
|
-
enabled,
|
|
1137
|
-
icons,
|
|
1138
|
-
...resource_or_options
|
|
1139
|
-
},
|
|
1140
|
-
execute,
|
|
1141
|
-
) {
|
|
1034
|
+
resource(resource_or_options, execute) {
|
|
1142
1035
|
if ('execute' in resource_or_options) {
|
|
1143
1036
|
// @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
|
|
1144
1037
|
// from showing in intellisense when declaring a tool inline
|
|
1145
1038
|
execute = resource_or_options.execute;
|
|
1146
1039
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
execute
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
});
|
|
1040
|
+
const stored_resource =
|
|
1041
|
+
/** @type {StoredResource & { uri: string }} */ (
|
|
1042
|
+
resource_or_options
|
|
1043
|
+
);
|
|
1044
|
+
stored_resource.execute = /** @type {NonNullable<typeof execute>} */ (
|
|
1045
|
+
execute
|
|
1046
|
+
);
|
|
1047
|
+
stored_resource.template = false;
|
|
1048
|
+
this.#resource(stored_resource);
|
|
1157
1049
|
}
|
|
1158
1050
|
/**
|
|
1159
1051
|
* Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
|
|
@@ -1191,37 +1083,23 @@ export class McpServer {
|
|
|
1191
1083
|
* @param {CreatedTemplate<TUri> | TemplateOptions<TUri>} template_or_options
|
|
1192
1084
|
* @param {(uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult} [execute]
|
|
1193
1085
|
*/
|
|
1194
|
-
template(
|
|
1195
|
-
{
|
|
1196
|
-
name,
|
|
1197
|
-
description,
|
|
1198
|
-
title,
|
|
1199
|
-
uri,
|
|
1200
|
-
complete,
|
|
1201
|
-
list: list_resources,
|
|
1202
|
-
enabled,
|
|
1203
|
-
icons,
|
|
1204
|
-
...template_or_options
|
|
1205
|
-
},
|
|
1206
|
-
execute,
|
|
1207
|
-
) {
|
|
1086
|
+
template(template_or_options, execute) {
|
|
1208
1087
|
if ('execute' in template_or_options) {
|
|
1209
1088
|
// @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
|
|
1210
1089
|
// from showing in intellisense when declaring a tool inline
|
|
1211
1090
|
execute = template_or_options.execute;
|
|
1212
1091
|
}
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
});
|
|
1092
|
+
const stored_template =
|
|
1093
|
+
/** @type {StoredResource & { uri: string }} */ (
|
|
1094
|
+
/** @type {unknown} */ (template_or_options)
|
|
1095
|
+
);
|
|
1096
|
+
stored_template.execute = /** @type {NonNullable<typeof execute>} */ (
|
|
1097
|
+
execute
|
|
1098
|
+
);
|
|
1099
|
+
// @ts-expect-error list_resources only exists on template resources
|
|
1100
|
+
stored_template.list_resources = template_or_options.list;
|
|
1101
|
+
stored_template.template = true;
|
|
1102
|
+
this.#resource(stored_template);
|
|
1225
1103
|
}
|
|
1226
1104
|
/**
|
|
1227
1105
|
* The main function that receive a JSONRpc message and either dispatch a `send` event or process the request.
|
|
@@ -46,7 +46,8 @@ export type ResourceOptions = {
|
|
|
46
46
|
name: string;
|
|
47
47
|
description: string;
|
|
48
48
|
title?: string;
|
|
49
|
-
uri: string
|
|
49
|
+
uri: string;
|
|
50
|
+
mimeType?: string;
|
|
50
51
|
enabled?: ()=>boolean | Promise<boolean>;
|
|
51
52
|
} & Icons
|
|
52
53
|
|
|
@@ -54,6 +55,7 @@ export type TemplateOptions<TUri extends string = string, TVariables extends Ext
|
|
|
54
55
|
name: string;
|
|
55
56
|
description: string;
|
|
56
57
|
title?: string;
|
|
58
|
+
mimeType?: string;
|
|
57
59
|
enabled?: ()=>boolean | Promise<boolean>;
|
|
58
60
|
uri: TUri;
|
|
59
61
|
complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
|
|
@@ -65,41 +67,26 @@ export type CreatedPrompt<TSchema extends StandardSchemaV1 | undefined = undefin
|
|
|
65
67
|
export type CreatedResource = ResourceOptions & { [created_resource]: created_resource };
|
|
66
68
|
export type CreatedTemplate<TUri extends string = string> = TemplateOptions<TUri> & { [created_template]: created_template };
|
|
67
69
|
|
|
68
|
-
export type Tool<TSchema extends StandardSchemaV1 = StandardSchemaV1<any>, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1<any>> = {
|
|
69
|
-
description: string;
|
|
70
|
-
schema: TSchema;
|
|
71
|
-
outputSchema?: TOutputSchema;
|
|
72
|
-
title?: string;
|
|
73
|
-
annotations?: ToolAnnotations;
|
|
74
|
-
_meta?: Record<string, unknown>;
|
|
75
|
-
enabled?: () => boolean | Promise<boolean>;
|
|
70
|
+
export type Tool<TSchema extends StandardSchemaV1 = StandardSchemaV1<any>, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1<any>> = ToolOptions<TSchema, TOutputSchema> & {
|
|
76
71
|
execute: (
|
|
77
72
|
input?: StandardSchemaV1.InferInput<TSchema>,
|
|
78
73
|
) => Promise<CallToolResult> | CallToolResult;
|
|
79
|
-
}
|
|
74
|
+
};
|
|
80
75
|
|
|
81
76
|
export type Completion = (
|
|
82
77
|
query: string,
|
|
83
78
|
context: { arguments: Record<string, string> },
|
|
84
79
|
) => CompleteResult | Promise<CompleteResult>;
|
|
85
80
|
|
|
86
|
-
export type Prompt<TSchema extends StandardSchemaV1 = StandardSchemaV1<any>> = {
|
|
87
|
-
description: string;
|
|
88
|
-
schema: TSchema;
|
|
89
|
-
title?: string;
|
|
90
|
-
enabled?: () => boolean | Promise<boolean>;
|
|
81
|
+
export type Prompt<TSchema extends StandardSchemaV1 = StandardSchemaV1<any>> = PromptOptions<TSchema> & {
|
|
91
82
|
execute: (
|
|
92
83
|
input?: StandardSchemaV1.InferInput<TSchema>,
|
|
93
84
|
) => Promise<GetPromptResult> | GetPromptResult;
|
|
94
|
-
}
|
|
85
|
+
};
|
|
95
86
|
|
|
96
87
|
export type StoredResource =
|
|
97
|
-
| {
|
|
98
|
-
description: string;
|
|
99
|
-
name: string;
|
|
88
|
+
| TemplateOptions<string, string> & {
|
|
100
89
|
template: true;
|
|
101
|
-
title?: string;
|
|
102
|
-
enabled?: () => boolean | Promise<boolean>;
|
|
103
90
|
list_resources?: () =>
|
|
104
91
|
| Promise<Array<Resource>>
|
|
105
92
|
| Array<Resource>;
|
|
@@ -107,17 +94,13 @@ export type StoredResource =
|
|
|
107
94
|
uri: string,
|
|
108
95
|
params: Record<string, string | string[]>,
|
|
109
96
|
) => Promise<ReadResourceResult> | ReadResourceResult;
|
|
110
|
-
}
|
|
111
|
-
| {
|
|
112
|
-
description: string;
|
|
113
|
-
name: string;
|
|
97
|
+
}
|
|
98
|
+
| ResourceOptions & {
|
|
114
99
|
template: false;
|
|
115
|
-
title?: string;
|
|
116
|
-
enabled?: () => boolean | Promise<boolean>;
|
|
117
100
|
execute: (
|
|
118
101
|
uri: string,
|
|
119
102
|
) => Promise<ReadResourceResult> | ReadResourceResult;
|
|
120
|
-
}
|
|
103
|
+
};
|
|
121
104
|
|
|
122
105
|
export type ServerOptions<TSchema extends StandardSchemaV1 | undefined> = {
|
|
123
106
|
capabilities?: ServerCapabilities;
|
package/src/resource.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
|
|
8
|
-
* Use the description and title to help the user to understand what the resource is.
|
|
8
|
+
* Use the description and title to help the user to understand what the resource is. The mimeType can be used to indicate the type of content.
|
|
9
9
|
*
|
|
10
10
|
* @param {ResourceOptions} options
|
|
11
11
|
* @param {(uri: string) => Promise<ReadResourceResult> | ReadResourceResult} execute
|
package/src/template.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Resource templates are used to create resources dynamically based on a URI template. The URI template should be a valid URI template as defined in RFC 6570.
|
|
11
11
|
* Resource templates can have a list method that returns a list of resources that match the template and a complete method that returns a list of resources given one of the template variables, this method will
|
|
12
12
|
* be invoked to provide completions for the template variables to the user.
|
|
13
|
-
* Use the description and title to help the user to understand what the resource is.
|
|
13
|
+
* Use the description and title to help the user to understand what the resource is. The mimeType can be used to indicate the type of content.
|
|
14
14
|
*
|
|
15
15
|
* @template {string} TUri
|
|
16
16
|
* @template {ExtractURITemplateVariables<TUri>} TVariables
|
package/src/types/index.d.ts
CHANGED
|
@@ -267,7 +267,8 @@ declare module 'tmcp' {
|
|
|
267
267
|
name: string;
|
|
268
268
|
description: string;
|
|
269
269
|
title?: string;
|
|
270
|
-
uri: string
|
|
270
|
+
uri: string;
|
|
271
|
+
mimeType?: string;
|
|
271
272
|
enabled?: ()=>boolean | Promise<boolean>;
|
|
272
273
|
} & Icons_1
|
|
273
274
|
|
|
@@ -275,6 +276,7 @@ declare module 'tmcp' {
|
|
|
275
276
|
name: string;
|
|
276
277
|
description: string;
|
|
277
278
|
title?: string;
|
|
279
|
+
mimeType?: string;
|
|
278
280
|
enabled?: ()=>boolean | Promise<boolean>;
|
|
279
281
|
uri: TUri;
|
|
280
282
|
complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
|
|
@@ -2437,7 +2439,7 @@ declare module 'tmcp/resource' {
|
|
|
2437
2439
|
*/
|
|
2438
2440
|
/**
|
|
2439
2441
|
* Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
|
|
2440
|
-
* Use the description and title to help the user to understand what the resource is.
|
|
2442
|
+
* Use the description and title to help the user to understand what the resource is. The mimeType can be used to indicate the type of content.
|
|
2441
2443
|
*
|
|
2442
2444
|
* */
|
|
2443
2445
|
export function defineResource(options: ResourceOptions, execute: (uri: string) => Promise<ReadResourceResult> | ReadResourceResult): CreatedResource;
|
|
@@ -2446,7 +2448,8 @@ declare module 'tmcp/resource' {
|
|
|
2446
2448
|
name: string;
|
|
2447
2449
|
description: string;
|
|
2448
2450
|
title?: string;
|
|
2449
|
-
uri: string
|
|
2451
|
+
uri: string;
|
|
2452
|
+
mimeType?: string;
|
|
2450
2453
|
enabled?: ()=>boolean | Promise<boolean>;
|
|
2451
2454
|
} & Icons
|
|
2452
2455
|
type CreatedResource = ResourceOptions & { [created_resource]: created_resource };
|
|
@@ -2545,7 +2548,7 @@ declare module 'tmcp/template' {
|
|
|
2545
2548
|
* Resource templates are used to create resources dynamically based on a URI template. The URI template should be a valid URI template as defined in RFC 6570.
|
|
2546
2549
|
* Resource templates can have a list method that returns a list of resources that match the template and a complete method that returns a list of resources given one of the template variables, this method will
|
|
2547
2550
|
* be invoked to provide completions for the template variables to the user.
|
|
2548
|
-
* Use the description and title to help the user to understand what the resource is.
|
|
2551
|
+
* Use the description and title to help the user to understand what the resource is. The mimeType can be used to indicate the type of content.
|
|
2549
2552
|
*
|
|
2550
2553
|
* */
|
|
2551
2554
|
export function defineTemplate<TUri extends string, TVariables extends ExtractURITemplateVariables<TUri>>(options: TemplateOptions<TUri>, execute: (uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult): CreatedTemplate<TUri>;
|
|
@@ -2599,6 +2602,7 @@ declare module 'tmcp/template' {
|
|
|
2599
2602
|
name: string;
|
|
2600
2603
|
description: string;
|
|
2601
2604
|
title?: string;
|
|
2605
|
+
mimeType?: string;
|
|
2602
2606
|
enabled?: ()=>boolean | Promise<boolean>;
|
|
2603
2607
|
uri: TUri;
|
|
2604
2608
|
complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
|
package/src/types/index.d.ts.map
CHANGED
|
@@ -103,6 +103,6 @@
|
|
|
103
103
|
null,
|
|
104
104
|
null
|
|
105
105
|
],
|
|
106
|
-
"mappings": ";;;;;cAkLaA,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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