@lowire/loop 0.0.4 → 0.0.5

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/index.d.ts CHANGED
@@ -16,4 +16,3 @@
16
16
 
17
17
  export * from './lib/types';
18
18
  export * from './lib/loop';
19
- export * from './lib/mcp/index';
package/index.js CHANGED
@@ -15,4 +15,3 @@
15
15
  */
16
16
 
17
17
  module.exports.Loop = require('./lib/loop').Loop;
18
- module.exports.createMcpTools = require('./lib/mcp/index').createMcpTools;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowire/loop",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Small agentic loop",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,34 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import type * as types from '../types';
17
- export type McpServer = {
18
- command: string;
19
- args?: string[];
20
- cwd?: string;
21
- stderr?: 'pipe' | 'inherit' | 'ignore';
22
- env?: Record<string, string>;
23
- };
24
- type ToolFilter = (string | RegExp)[];
25
- type ToolSupport = {
26
- close: () => Promise<void>;
27
- tools: types.Tool[];
28
- callTool: types.ToolCallback;
29
- };
30
- export declare function createMcpTools(servers: Record<string, McpServer>, options?: {
31
- rootDir?: string;
32
- toolFilter?: ToolFilter;
33
- }): Promise<ToolSupport>;
34
- export {};
package/lib/mcp/index.js DELETED
@@ -1,109 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || (function () {
34
- var ownKeys = function(o) {
35
- ownKeys = Object.getOwnPropertyNames || function (o) {
36
- var ar = [];
37
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
- return ar;
39
- };
40
- return ownKeys(o);
41
- };
42
- return function (mod) {
43
- if (mod && mod.__esModule) return mod;
44
- var result = {};
45
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
- __setModuleDefault(result, mod);
47
- return result;
48
- };
49
- })();
50
- var __importDefault = (this && this.__importDefault) || function (mod) {
51
- return (mod && mod.__esModule) ? mod : { "default": mod };
52
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.createMcpTools = createMcpTools;
55
- const url_1 = __importDefault(require("url"));
56
- async function connectToMcpServer(server, options) {
57
- const { Client } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/client/index.js')));
58
- const { StdioClientTransport } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/client/stdio.js')));
59
- const { ListRootsRequestSchema } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/types.js')));
60
- const transport = new StdioClientTransport(server);
61
- const capabilities = {};
62
- if (options?.rootDir)
63
- capabilities['roots'] = {};
64
- const client = new Client({ name: 'test', version: '1.0.0' }, { capabilities });
65
- if (options?.rootDir) {
66
- client.setRequestHandler(ListRootsRequestSchema, async () => {
67
- return {
68
- roots: [{ name: 'workspace', uri: url_1.default.pathToFileURL(options.rootDir).toString() }],
69
- };
70
- });
71
- }
72
- await client.connect(transport);
73
- return client;
74
- }
75
- async function mcpTools(server, options) {
76
- const client = await connectToMcpServer(server, options);
77
- const { tools } = await client.listTools();
78
- const filteredTools = options?.toolFilter ? tools.filter(tool => options.toolFilter.some(filter => typeof filter === 'string' ? tool.name === filter : filter.test(tool.name))) : tools;
79
- const callTool = async (params) => {
80
- return await client.callTool({ name: params.name, arguments: params.arguments });
81
- };
82
- return { tools: filteredTools, callTool, close: () => client.close() };
83
- }
84
- async function createMcpTools(servers, options) {
85
- const allTools = [];
86
- const callTools = new Map();
87
- const closes = [];
88
- for (const [name, server] of Object.entries(servers)) {
89
- const { tools, callTool, close } = await mcpTools(server, options);
90
- for (const tool of tools) {
91
- const fullName = `${name}__${tool.name}`;
92
- allTools.push({ ...tool, name: fullName });
93
- callTools.set(fullName, params => callTool({ name: tool.name, arguments: params.arguments }));
94
- }
95
- closes.push(close);
96
- }
97
- return {
98
- close: async () => {
99
- await Promise.all(closes.map(c => c()));
100
- },
101
- tools: allTools,
102
- callTool: async (params) => {
103
- const callTool = callTools.get(params.name);
104
- if (!callTool)
105
- throw new Error(`Tool not found: ${params.name}`);
106
- return callTool(params);
107
- }
108
- };
109
- }