@jalpp/mcp-adapter 0.1.0 → 0.1.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/dist/index.js CHANGED
@@ -1,30 +1,3 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- toolAdapter: () => toolAdapter,
24
- toolContentAdapter: () => toolContentAdapter
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
-
28
1
  // src/toolAdapter.ts
29
2
  function toolContentAdapter(data, error) {
30
3
  return {
@@ -51,8 +24,7 @@ function toolAdapter(server, toolInputAdapter) {
51
24
  );
52
25
  }
53
26
  }
54
- // Annotate the CommonJS export names for ESM import in node:
55
- 0 && (module.exports = {
27
+ export {
56
28
  toolAdapter,
57
29
  toolContentAdapter
58
- });
30
+ };
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@jalpp/mcp-adapter",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Adapter utilities for registering MCP tools",
5
5
  "author": "jalpp",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/jalpp/mcp-adapter.git"
9
9
  },
10
- "main": "./dist/index.cjs",
10
+ "type": "module",
11
+ "main": "./dist/index.js",
11
12
  "module": "./dist/index.js",
12
13
  "types": "./dist/index.d.ts",
13
14
  "exports": {
14
15
  ".": {
15
16
  "import": "./dist/index.js",
16
- "require": "./dist/index.cjs",
17
17
  "types": "./dist/index.d.ts"
18
18
  }
19
19
  },
package/dist/index.d.mts DELETED
@@ -1,95 +0,0 @@
1
- import { McpServer, ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import { ZodRawShapeCompat } from '@modelcontextprotocol/sdk/server/zod-compat.js';
3
- import { ToolAnnotations, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
4
-
5
- /**
6
- * Adapter input for registering a tool that declares an input schema.
7
- * The generic parameter `T` is inferred from the `inputSchema` shape and
8
- * flows through to `cb`, ensuring the callback receives correctly-typed args.
9
- *
10
- * @template T - A Zod raw shape (e.g. `{ fen: z.ZodString }`) that defines the tool's input.
11
- */
12
- interface ToolInputAdapterWithSchema<T extends ZodRawShapeCompat> {
13
- /** Unique tool name used to identify the tool in the MCP registry. */
14
- name: string;
15
- config: {
16
- /** Optional human-readable display title. */
17
- title?: string;
18
- /** Description of what the tool does, shown to the model. */
19
- description?: string;
20
- /** Zod shape defining the tool's input arguments. */
21
- inputSchema: T;
22
- /** Optional Zod shape defining the tool's structured output. */
23
- outputSchema?: ZodRawShapeCompat;
24
- /** Behavioural hints for the model (e.g. `openWorldHint`, `readOnlyHint`). */
25
- annotations?: ToolAnnotations;
26
- /** Arbitrary metadata attached to the tool registration. */
27
- _meta?: Record<string, unknown>;
28
- };
29
- /**
30
- * Tool handler callback. Receives parsed, type-safe args derived from `inputSchema`
31
- * plus a `RequestHandlerExtra` context object.
32
- */
33
- cb: ToolCallback<T>;
34
- }
35
- /**
36
- * Adapter input for registering a tool that takes no input arguments.
37
- * The callback receives only the `RequestHandlerExtra` context object.
38
- */
39
- interface ToolInputAdapterWithoutSchema {
40
- /** Unique tool name used to identify the tool in the MCP registry. */
41
- name: string;
42
- config: {
43
- /** Optional human-readable display title. */
44
- title?: string;
45
- /** Description of what the tool does, shown to the model. */
46
- description?: string;
47
- inputSchema?: undefined;
48
- /** Optional Zod shape defining the tool's structured output. */
49
- outputSchema?: ZodRawShapeCompat;
50
- /** Behavioural hints for the model (e.g. `openWorldHint`, `readOnlyHint`). */
51
- annotations?: ToolAnnotations;
52
- /** Arbitrary metadata attached to the tool registration. */
53
- _meta?: Record<string, unknown>;
54
- };
55
- /**
56
- * Tool handler callback. Receives only a `RequestHandlerExtra` context object
57
- * since no input schema is defined.
58
- */
59
- cb: ToolCallback<undefined>;
60
- }
61
- /**
62
- * Normalizes a tool result into a standard `CallToolResult` text content block.
63
- *
64
- * If `error` is provided it is used as the text content; otherwise `data` is
65
- * serialized to a pretty-printed JSON string.
66
- *
67
- * @param data - The successful result payload. Used when `error` is absent.
68
- * @param error - An error message string. Takes priority over `data` when present.
69
- * @returns A `CallToolResult` with a single `text` content block.
70
- *
71
- * @example
72
- * const { data, error } = await service.getData();
73
- * return toolContentAdapter(data ?? {}, error);
74
- */
75
- declare function toolContentAdapter(data: object, error: string | undefined): CallToolResult;
76
- /**
77
- * Registers a tool that declares an input schema on an MCP server.
78
- *
79
- * The generic `T` is inferred from `toolInputAdapter.config.inputSchema`, making
80
- * the callback args fully type-safe without manual annotation.
81
- *
82
- * @template T - Zod raw shape inferred from the provided `inputSchema`.
83
- * @param server - The `McpServer` instance to register the tool on.
84
- * @param toolInputAdapter - Adapter object containing the tool name, config, and typed callback.
85
- */
86
- declare function toolAdapter<T extends ZodRawShapeCompat>(server: McpServer, toolInputAdapter: ToolInputAdapterWithSchema<T>): void;
87
- /**
88
- * Registers a tool that takes no input arguments on an MCP server.
89
- *
90
- * @param server - The `McpServer` instance to register the tool on.
91
- * @param toolInputAdapter - Adapter object containing the tool name, config, and no-arg callback.
92
- */
93
- declare function toolAdapter(server: McpServer, toolInputAdapter: ToolInputAdapterWithoutSchema): void;
94
-
95
- export { toolAdapter, toolContentAdapter };
package/dist/index.mjs DELETED
@@ -1,30 +0,0 @@
1
- // src/toolAdapter.ts
2
- function toolContentAdapter(data, error) {
3
- return {
4
- content: [
5
- {
6
- type: "text",
7
- text: error || JSON.stringify(data, null, 2)
8
- }
9
- ]
10
- };
11
- }
12
- function toolAdapter(server, toolInputAdapter) {
13
- if (toolInputAdapter.config.inputSchema) {
14
- server.registerTool(
15
- toolInputAdapter.name,
16
- toolInputAdapter.config,
17
- toolInputAdapter.cb
18
- );
19
- } else {
20
- server.registerTool(
21
- toolInputAdapter.name,
22
- toolInputAdapter.config,
23
- toolInputAdapter.cb
24
- );
25
- }
26
- }
27
- export {
28
- toolAdapter,
29
- toolContentAdapter
30
- };