@theorvane/type-mcp 0.2.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/LICENSE +21 -0
- package/README.md +151 -0
- package/dist/chunk-64DS4UNF.js +106 -0
- package/dist/chunk-64DS4UNF.js.map +1 -0
- package/dist/http.cjs +114 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +24 -0
- package/dist/http.d.ts +24 -0
- package/dist/http.js +89 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +438 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +51 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +318 -0
- package/dist/index.js.map +1 -0
- package/dist/instance-resolver-BdKelIch.d.cts +46 -0
- package/dist/instance-resolver-BdKelIch.d.ts +46 -0
- package/dist/langchain.cjs +161 -0
- package/dist/langchain.cjs.map +1 -0
- package/dist/langchain.d.cts +11 -0
- package/dist/langchain.d.ts +11 -0
- package/dist/langchain.js +43 -0
- package/dist/langchain.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readMcpServerDefinition,
|
|
3
|
+
resolveMcpServerInstance
|
|
4
|
+
} from "./chunk-64DS4UNF.js";
|
|
5
|
+
|
|
6
|
+
// src/langchain/create-langchain-tools.ts
|
|
7
|
+
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
8
|
+
var TOOL_EXECUTION_FAILED = "Tool execution failed";
|
|
9
|
+
async function createLangChainTools(serverClass, options) {
|
|
10
|
+
const definition = readMcpServerDefinition(serverClass);
|
|
11
|
+
const instance = options ? await resolveMcpServerInstance(serverClass, options.resolver) : await resolveMcpServerInstance(
|
|
12
|
+
serverClass
|
|
13
|
+
);
|
|
14
|
+
return definition.tools.map((tool) => createLangChainTool(instance, tool));
|
|
15
|
+
}
|
|
16
|
+
function createLangChainTool(instance, definition) {
|
|
17
|
+
return new DynamicStructuredTool({
|
|
18
|
+
name: definition.name,
|
|
19
|
+
description: definition.description ?? `${definition.name} tool`,
|
|
20
|
+
schema: definition.input,
|
|
21
|
+
func: async (input) => invokeSafely(instance, definition.methodName, input)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function invokeSafely(instance, methodName, input) {
|
|
25
|
+
try {
|
|
26
|
+
const method = Reflect.get(instance, methodName);
|
|
27
|
+
if (typeof method !== "function") {
|
|
28
|
+
return TOOL_EXECUTION_FAILED;
|
|
29
|
+
}
|
|
30
|
+
const result = await Reflect.apply(method, instance, [input]);
|
|
31
|
+
if (typeof result === "string") {
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
const serialized = JSON.stringify(result);
|
|
35
|
+
return serialized === void 0 ? TOOL_EXECUTION_FAILED : serialized;
|
|
36
|
+
} catch {
|
|
37
|
+
return TOOL_EXECUTION_FAILED;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
createLangChainTools
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=langchain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/langchain/create-langchain-tools.ts"],"sourcesContent":["import { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { readMcpServerDefinition } from \"../metadata/read-server-definition.js\";\nimport type { InstanceResolver } from \"../resolver/instance-resolver.js\";\nimport { resolveMcpServerInstance } from \"../resolver/resolve-server-instance.js\";\nimport type {\n\tMcpServerConstructor,\n\tMcpToolDefinition,\n\tZeroArgumentMcpServerConstructor,\n} from \"../types.js\";\n\nconst TOOL_EXECUTION_FAILED = \"Tool execution failed\";\n\nexport interface CreateLangChainToolsOptions<T extends object> {\n\treadonly resolver: InstanceResolver<T>;\n}\n\nexport function createLangChainTools<T extends object>(\n\tserverClass: ZeroArgumentMcpServerConstructor<T>,\n): Promise<readonly DynamicStructuredTool[]>;\nexport function createLangChainTools<\n\tT extends object,\n\tArguments extends readonly unknown[],\n>(\n\tserverClass: McpServerConstructor<T, Arguments>,\n\toptions: CreateLangChainToolsOptions<T>,\n): Promise<readonly DynamicStructuredTool[]>;\nexport async function createLangChainTools<\n\tT extends object,\n\tArguments extends readonly unknown[],\n>(\n\tserverClass: McpServerConstructor<T, Arguments>,\n\toptions?: CreateLangChainToolsOptions<T>,\n): Promise<readonly DynamicStructuredTool[]> {\n\tconst definition = readMcpServerDefinition(serverClass);\n\tconst instance = options\n\t\t? await resolveMcpServerInstance(serverClass, options.resolver)\n\t\t: await resolveMcpServerInstance(\n\t\t\t\tserverClass as ZeroArgumentMcpServerConstructor<T>,\n\t\t\t);\n\n\treturn definition.tools.map((tool) => createLangChainTool(instance, tool));\n}\n\nfunction createLangChainTool(\n\tinstance: object,\n\tdefinition: McpToolDefinition,\n): DynamicStructuredTool {\n\treturn new DynamicStructuredTool({\n\t\tname: definition.name,\n\t\tdescription: definition.description ?? `${definition.name} tool`,\n\t\tschema: definition.input,\n\t\tfunc: async (input) => invokeSafely(instance, definition.methodName, input),\n\t});\n}\n\nasync function invokeSafely(\n\tinstance: object,\n\tmethodName: string,\n\tinput: unknown,\n): Promise<string> {\n\ttry {\n\t\tconst method = Reflect.get(instance, methodName);\n\t\tif (typeof method !== \"function\") {\n\t\t\treturn TOOL_EXECUTION_FAILED;\n\t\t}\n\n\t\tconst result = await Reflect.apply(method, instance, [input]);\n\t\tif (typeof result === \"string\") {\n\t\t\treturn result;\n\t\t}\n\n\t\tconst serialized = JSON.stringify(result);\n\t\treturn serialized === undefined ? TOOL_EXECUTION_FAILED : serialized;\n\t} catch {\n\t\treturn TOOL_EXECUTION_FAILED;\n\t}\n}\n"],"mappings":";;;;;;AAAA,SAAS,6BAA6B;AAUtC,IAAM,wBAAwB;AAgB9B,eAAsB,qBAIrB,aACA,SAC4C;AAC5C,QAAM,aAAa,wBAAwB,WAAW;AACtD,QAAM,WAAW,UACd,MAAM,yBAAyB,aAAa,QAAQ,QAAQ,IAC5D,MAAM;AAAA,IACN;AAAA,EACD;AAEF,SAAO,WAAW,MAAM,IAAI,CAAC,SAAS,oBAAoB,UAAU,IAAI,CAAC;AAC1E;AAEA,SAAS,oBACR,UACA,YACwB;AACxB,SAAO,IAAI,sBAAsB;AAAA,IAChC,MAAM,WAAW;AAAA,IACjB,aAAa,WAAW,eAAe,GAAG,WAAW,IAAI;AAAA,IACzD,QAAQ,WAAW;AAAA,IACnB,MAAM,OAAO,UAAU,aAAa,UAAU,WAAW,YAAY,KAAK;AAAA,EAC3E,CAAC;AACF;AAEA,eAAe,aACd,UACA,YACA,OACkB;AAClB,MAAI;AACH,UAAM,SAAS,QAAQ,IAAI,UAAU,UAAU;AAC/C,QAAI,OAAO,WAAW,YAAY;AACjC,aAAO;AAAA,IACR;AAEA,UAAM,SAAS,MAAM,QAAQ,MAAM,QAAQ,UAAU,CAAC,KAAK,CAAC;AAC5D,QAAI,OAAO,WAAW,UAAU;AAC/B,aAAO;AAAA,IACR;AAEA,UAAM,aAAa,KAAK,UAAU,MAAM;AACxC,WAAO,eAAe,SAAY,wBAAwB;AAAA,EAC3D,QAAQ;AACP,WAAO;AAAA,EACR;AACD;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theorvane/type-mcp",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Decorator-first TypeScript framework for Model Context Protocol servers",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Theorvane/type-mcp.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://typemcp.theorvane.tech",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/Theorvane/type-mcp/issues"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./http": {
|
|
25
|
+
"types": "./dist/http.d.ts",
|
|
26
|
+
"import": "./dist/http.js",
|
|
27
|
+
"require": "./dist/http.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./langchain": {
|
|
30
|
+
"types": "./dist/langchain.d.ts",
|
|
31
|
+
"import": "./dist/langchain.js",
|
|
32
|
+
"require": "./dist/langchain.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"packageManager": "npm@10.9.7",
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=20"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.type-tests.json",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"lint": "biome check .",
|
|
52
|
+
"build": "tsup",
|
|
53
|
+
"verify:package": "node scripts/verify-package-exports.mjs",
|
|
54
|
+
"verify:publish": "npm run build && node scripts/verify-publish-readiness.mjs",
|
|
55
|
+
"example:standalone-http": "npm run build && npm --prefix examples/standalone-http ci && npm --prefix examples/standalone-http run build",
|
|
56
|
+
"example:langgraph-tools": "npm run build && npm --prefix examples/langgraph-tools ci && npm --prefix examples/langgraph-tools run build",
|
|
57
|
+
"prepublishOnly": "npm run verify:publish",
|
|
58
|
+
"clean": "rimraf dist coverage"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@modelcontextprotocol/sdk": "1.26.0",
|
|
62
|
+
"zod": "^4.4.3"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@biomejs/biome": "^2.5.4",
|
|
66
|
+
"@langchain/core": "1.2.3",
|
|
67
|
+
"@langchain/langgraph": "1.4.8",
|
|
68
|
+
"@types/node": "^22.15.3",
|
|
69
|
+
"rimraf": "^6.0.1",
|
|
70
|
+
"tsup": "^8.5.1",
|
|
71
|
+
"typescript": "^5.8.3",
|
|
72
|
+
"vitest": "^4.1.10"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@langchain/core": "^1.2.3"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"@langchain/core": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|