@mcphero/core 1.1.6

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.
@@ -0,0 +1,18 @@
1
+
2
+ 
3
+ > @mcphero/core@1.1.6 build /Users/atomic/projects/ai/mcphero/packages/core
4
+ > tsup
5
+
6
+ CLI Building entry: src/index.ts
7
+ CLI Using tsconfig: tsconfig.json
8
+ CLI tsup v8.5.1
9
+ CLI Using tsup config: /Users/atomic/projects/ai/mcphero/packages/core/tsup.config.ts
10
+ CLI Target: node18
11
+ CLI Cleaning output folder
12
+ ESM Build start
13
+ ESM build/index.js 2.88 KB
14
+ ESM build/index.js.map 7.15 KB
15
+ ESM ⚡️ Build success in 6ms
16
+ DTS Build start
17
+ DTS ⚡️ Build success in 590ms
18
+ DTS build/index.d.ts 2.50 KB
@@ -0,0 +1,17 @@
1
+
2
+ > @mcphero/core@1.1.6 check /Users/atomic/projects/ai/mcphero/packages/core
3
+ > pnpm lint && pnpm typecheck
4
+
5
+
6
+ > @mcphero/core@1.1.6 lint /Users/atomic/projects/ai/mcphero/packages/core
7
+ > eslint
8
+
9
+
10
+ /Users/atomic/projects/ai/mcphero/packages/core/src/index.ts
11
+ 8:1 error Too many blank lines at the end of file. Max of 0 allowed @stylistic/no-multiple-empty-lines
12
+
13
+ ✖ 1 problem (1 error, 0 warnings)
14
+ 1 error and 0 warnings potentially fixable with the `--fix` option.
15
+
16
+  ELIFECYCLE  Command failed with exit code 1.
17
+  ELIFECYCLE  Command failed with exit code 1.
@@ -0,0 +1,5 @@
1
+
2
+ 
3
+ > @mcphero/core@1.1.6 lint /Users/atomic/projects/ai/mcphero/packages/core
4
+ > eslint
5
+
@@ -0,0 +1,26 @@
1
+
2
+ 
3
+ > @mcphero/core@1.1.6 prepack /Users/atomic/projects/ai/mcphero/packages/core
4
+ > pnpm clean && pnpm build
5
+
6
+
7
+ > @mcphero/core@1.1.6 clean /Users/atomic/projects/ai/mcphero/packages/core
8
+ > rimraf build
9
+
10
+
11
+ > @mcphero/core@1.1.6 build /Users/atomic/projects/ai/mcphero/packages/core
12
+ > tsup
13
+
14
+ CLI Building entry: src/index.ts
15
+ CLI Using tsconfig: tsconfig.json
16
+ CLI tsup v8.5.1
17
+ CLI Using tsup config: /Users/atomic/projects/ai/mcphero/packages/core/tsup.config.ts
18
+ CLI Target: node18
19
+ CLI Cleaning output folder
20
+ ESM Build start
21
+ ESM build/index.js 2.88 KB
22
+ ESM build/index.js.map 7.15 KB
23
+ ESM ⚡️ Build success in 6ms
24
+ DTS Build start
25
+ DTS ⚡️ Build success in 614ms
26
+ DTS build/index.d.ts 2.50 KB
@@ -0,0 +1,70 @@
1
+ import z, { z as z$1 } from 'zod';
2
+ import { TextContent } from '@modelcontextprotocol/sdk/types.js';
3
+
4
+ interface MCPHeroContext {
5
+ keys: () => string[];
6
+ has: (key: string) => boolean;
7
+ get: <T>(key: string) => T;
8
+ set: <T>(key: string, value: T) => void;
9
+ fork: (store?: Record<string, unknown>) => MCPHeroContext;
10
+ }
11
+ declare function createContext(store?: Record<string, unknown>): MCPHeroContext;
12
+
13
+ interface Action<I extends object = any, O extends object = any> {
14
+ name: string;
15
+ description: string;
16
+ input: z.ZodType<I> & {
17
+ shape: Record<string, z.ZodTypeAny>;
18
+ };
19
+ args?: (keyof I)[];
20
+ isEnabled?: (context: MCPHeroContext) => boolean;
21
+ run: (input: I, context: MCPHeroContext) => Promise<O>;
22
+ }
23
+ declare function createAction<I extends object = object, O extends object = object>(action: Action<I, O>): Action<I, O>;
24
+
25
+ interface Adapter {
26
+ context: MCPHeroContext;
27
+ start(actions: Action[]): Promise<void>;
28
+ stop(): Promise<void>;
29
+ }
30
+ type AdapterGenerator = (options: MCPHeroOptions, baseContext: MCPHeroContext) => Adapter;
31
+ type AdapterFactory<T = void> = (options: T) => AdapterGenerator;
32
+
33
+ interface MCPHeroOptions {
34
+ name: string;
35
+ description: string;
36
+ version: string;
37
+ }
38
+ interface MCPHero {
39
+ set: <T>(key: string, value: T) => MCPHero;
40
+ adapter: (generator: AdapterGenerator) => MCPHero;
41
+ action: (action: Action) => MCPHero;
42
+ actions: (actions: Action[]) => MCPHero;
43
+ start: () => Promise<MCPHero>;
44
+ }
45
+ declare function mcphero(options: MCPHeroOptions): MCPHero;
46
+
47
+ interface ToolResponse {
48
+ content: TextContent[];
49
+ [x: string]: unknown;
50
+ }
51
+ declare function toolResponse(data: object): ToolResponse;
52
+ declare function parseToolResponse<T = unknown>(result: ToolResponse): T;
53
+
54
+ interface SideloadResource {
55
+ id: string;
56
+ name: string;
57
+ contentType: string;
58
+ size: number;
59
+ }
60
+ declare function createSideloadResource(buffer: Buffer, { name, contentType }: Pick<SideloadResource, 'name' | 'contentType'>): Promise<SideloadResource>;
61
+
62
+ interface UnwrapResult {
63
+ defaultValue?: any;
64
+ isOptional?: boolean;
65
+ isNullable?: boolean;
66
+ isReadOnly?: boolean;
67
+ }
68
+ declare function unwrap(type: z$1.ZodTypeAny, result?: UnwrapResult): [z$1.ZodTypeAny, UnwrapResult];
69
+
70
+ export { type Action, type Adapter, type AdapterFactory, type AdapterGenerator, type MCPHero, type MCPHeroContext, type MCPHeroOptions, type SideloadResource, type ToolResponse, type UnwrapResult, createAction, createContext, createSideloadResource, mcphero, parseToolResponse, toolResponse, unwrap };
package/build/index.js ADDED
@@ -0,0 +1,120 @@
1
+ // src/util/context.ts
2
+ function createContext(store = {}) {
3
+ return {
4
+ keys: () => {
5
+ return Object.keys(store);
6
+ },
7
+ has: (key) => {
8
+ return store[key] != null;
9
+ },
10
+ get: (key) => {
11
+ const value = store[key];
12
+ if (value == null) {
13
+ throw new Error(`Invalid context key: ${key}`);
14
+ }
15
+ return value;
16
+ },
17
+ set: (key, value) => {
18
+ store[key] = value;
19
+ },
20
+ fork: (value) => {
21
+ return createContext({ ...store, ...value });
22
+ }
23
+ };
24
+ }
25
+
26
+ // src/lib/mcphero.ts
27
+ function mcphero(options) {
28
+ const adapters = [];
29
+ const actions = [];
30
+ const context = createContext();
31
+ const builder = {
32
+ set: (key, value) => {
33
+ context.set(key, value);
34
+ return builder;
35
+ },
36
+ adapter: (generator) => {
37
+ adapters.push(generator(options, context));
38
+ return builder;
39
+ },
40
+ action: (value) => {
41
+ actions.push(value);
42
+ return builder;
43
+ },
44
+ actions: (values) => {
45
+ actions.push(...values);
46
+ return builder;
47
+ },
48
+ start: async () => {
49
+ await Promise.all(adapters.map((adapter) => {
50
+ return adapter.start(actions.filter((action) => {
51
+ if (!action.isEnabled) {
52
+ return true;
53
+ }
54
+ return action.isEnabled(adapter.context);
55
+ }));
56
+ }));
57
+ return builder;
58
+ }
59
+ };
60
+ return builder;
61
+ }
62
+
63
+ // src/util/action.ts
64
+ function createAction(action) {
65
+ return action;
66
+ }
67
+
68
+ // src/util/mcp.ts
69
+ function toolResponse(data) {
70
+ return {
71
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
72
+ };
73
+ }
74
+ function parseToolResponse(result) {
75
+ const text = result.content[0].text;
76
+ return JSON.parse(text);
77
+ }
78
+
79
+ // src/util/sideload.ts
80
+ import { randomUUID } from "crypto";
81
+ import { writeFile } from "fs/promises";
82
+ async function createSideloadResource(buffer, { name, contentType }) {
83
+ const id = randomUUID();
84
+ const resource = { id, name, contentType, size: buffer.length };
85
+ await Promise.all([
86
+ writeFile(`resources/${id}`, buffer),
87
+ writeFile(`resources/${id}.json`, JSON.stringify(resource), "utf-8")
88
+ ]);
89
+ return resource;
90
+ }
91
+
92
+ // src/util/zod.ts
93
+ import { z } from "zod";
94
+ function unwrap(type, result = {}) {
95
+ if (type instanceof z.ZodOptional) {
96
+ result.isOptional = true;
97
+ return unwrap(type.unwrap(), result);
98
+ } else if (type instanceof z.ZodNullable) {
99
+ result.isNullable = true;
100
+ return unwrap(type.unwrap(), result);
101
+ } else if (type instanceof z.ZodReadonly) {
102
+ result.isReadOnly = true;
103
+ return unwrap(type.unwrap(), result);
104
+ } else if (type instanceof z.ZodDefault) {
105
+ result.defaultValue = typeof type.def.defaultValue === "function" ? type.def.defaultValue() : type.def.defaultValue;
106
+ return unwrap(type.unwrap(), result);
107
+ } else {
108
+ return [type, result];
109
+ }
110
+ }
111
+ export {
112
+ createAction,
113
+ createContext,
114
+ createSideloadResource,
115
+ mcphero,
116
+ parseToolResponse,
117
+ toolResponse,
118
+ unwrap
119
+ };
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/util/context.ts","../src/lib/mcphero.ts","../src/util/action.ts","../src/util/mcp.ts","../src/util/sideload.ts","../src/util/zod.ts"],"sourcesContent":["export interface MCPHeroContext {\n keys: () => string[]\n has: (key: string) => boolean\n get: <T>(key: string) => T\n set: <T>(key: string, value: T) => void\n fork: (store?: Record<string, unknown>) => MCPHeroContext\n}\n\nexport function createContext(store: Record<string, unknown> = {}): MCPHeroContext {\n return {\n keys: () => {\n return Object.keys(store)\n },\n has: (key: string): boolean => {\n return store[key] != null\n },\n get: <T>(key: string): T => {\n const value = store[key]\n if (value == null) { throw new Error(`Invalid context key: ${key}`) }\n return value as T\n },\n set: <T>(key: string, value: T) => {\n store[key] = value\n },\n fork: (value?: Record<string, unknown>) => {\n return createContext({ ...store, ...value })\n }\n }\n}\n","import { Action } from '../util/action.js'\nimport { Adapter, AdapterGenerator } from '../util/adapter.js'\nimport { createContext } from '../util/context.js'\n\nexport interface MCPHeroOptions {\n name: string\n description: string\n version: string\n}\n\nexport interface MCPHero {\n set: <T>(key: string, value: T) => MCPHero\n adapter: (generator: AdapterGenerator) => MCPHero\n action: (action: Action) => MCPHero\n actions: (actions: Action[]) => MCPHero\n start: () => Promise<MCPHero>\n}\n\nexport function mcphero(options: MCPHeroOptions): MCPHero {\n const adapters: Adapter[] = []\n const actions: Action[] = []\n const context = createContext()\n const builder: MCPHero = {\n set: (key, value) => {\n context.set(key, value)\n return builder\n },\n adapter: (generator) => {\n adapters.push(generator(options, context))\n return builder\n },\n action: (value) => {\n actions.push(value)\n return builder\n },\n actions: (values) => {\n actions.push(...values)\n return builder\n },\n start: async () => {\n await Promise.all(adapters.map((adapter) => {\n return adapter.start(actions.filter((action) => {\n if (!action.isEnabled) { return true }\n return action.isEnabled(adapter.context)\n }))\n }))\n return builder\n }\n }\n return builder\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport z from 'zod'\nimport { MCPHeroContext } from './context.js'\n\nexport interface Action<I extends object = any, O extends object = any> {\n name: string\n description: string\n input: z.ZodType<I> & { shape: Record<string, z.ZodTypeAny> }\n args?: (keyof I)[]\n isEnabled?: (context: MCPHeroContext) => boolean\n run: (input: I, context: MCPHeroContext) => Promise<O>\n}\n\nexport function createAction<I extends object = object, O extends object = object>(\n action: Action<I, O>\n): Action<I, O> {\n return action\n}\n","import { TextContent } from '@modelcontextprotocol/sdk/types.js'\n\nexport interface ToolResponse {\n content: TextContent[]\n [x: string]: unknown\n}\n\nexport function toolResponse(data: object): ToolResponse {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }]\n }\n}\n\nexport function parseToolResponse<T = unknown>(result: ToolResponse): T {\n const text = result.content[0].text\n return JSON.parse(text)\n}\n","import { randomUUID } from 'crypto'\nimport { writeFile } from 'fs/promises'\n\nexport interface SideloadResource {\n id: string\n name: string\n contentType: string\n size: number\n}\n\nexport async function createSideloadResource(buffer: Buffer, { name, contentType }: Pick<SideloadResource, 'name' | 'contentType'>) {\n const id = randomUUID()\n const resource: SideloadResource = { id, name, contentType, size: buffer.length }\n await Promise.all([\n writeFile(`resources/${id}`, buffer),\n writeFile(`resources/${id}.json`, JSON.stringify(resource), 'utf-8')\n ])\n return resource\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { z } from 'zod'\n\nexport interface UnwrapResult {\n defaultValue?: any\n isOptional?: boolean\n isNullable?: boolean\n isReadOnly?: boolean\n}\n\nexport function unwrap(\n type: z.ZodTypeAny,\n result: UnwrapResult = {}\n): [z.ZodTypeAny, UnwrapResult] {\n if (type instanceof z.ZodOptional) {\n result.isOptional = true\n return unwrap(type.unwrap() as z.ZodTypeAny, result)\n } else if (type instanceof z.ZodNullable) {\n result.isNullable = true\n return unwrap(type.unwrap() as z.ZodTypeAny, result)\n } else if (type instanceof z.ZodReadonly) {\n result.isReadOnly = true\n return unwrap(type.unwrap() as z.ZodTypeAny, result)\n } else if (type instanceof z.ZodDefault) {\n result.defaultValue = typeof type.def.defaultValue === 'function'\n ? type.def.defaultValue()\n : type.def.defaultValue\n return unwrap(type.unwrap() as z.ZodTypeAny, result)\n } else {\n return [type, result]\n }\n}\n"],"mappings":";AAQO,SAAS,cAAc,QAAiC,CAAC,GAAmB;AACjF,SAAO;AAAA,IACL,MAAM,MAAM;AACV,aAAO,OAAO,KAAK,KAAK;AAAA,IAC1B;AAAA,IACA,KAAK,CAAC,QAAyB;AAC7B,aAAO,MAAM,GAAG,KAAK;AAAA,IACvB;AAAA,IACA,KAAK,CAAI,QAAmB;AAC1B,YAAM,QAAQ,MAAM,GAAG;AACvB,UAAI,SAAS,MAAM;AAAE,cAAM,IAAI,MAAM,wBAAwB,GAAG,EAAE;AAAA,MAAE;AACpE,aAAO;AAAA,IACT;AAAA,IACA,KAAK,CAAI,KAAa,UAAa;AACjC,YAAM,GAAG,IAAI;AAAA,IACf;AAAA,IACA,MAAM,CAAC,UAAoC;AACzC,aAAO,cAAc,EAAE,GAAG,OAAO,GAAG,MAAM,CAAC;AAAA,IAC7C;AAAA,EACF;AACF;;;ACVO,SAAS,QAAQ,SAAkC;AACxD,QAAM,WAAsB,CAAC;AAC7B,QAAM,UAAoB,CAAC;AAC3B,QAAM,UAAU,cAAc;AAC9B,QAAM,UAAmB;AAAA,IACvB,KAAK,CAAC,KAAK,UAAU;AACnB,cAAQ,IAAI,KAAK,KAAK;AACtB,aAAO;AAAA,IACT;AAAA,IACA,SAAS,CAAC,cAAc;AACtB,eAAS,KAAK,UAAU,SAAS,OAAO,CAAC;AACzC,aAAO;AAAA,IACT;AAAA,IACA,QAAQ,CAAC,UAAU;AACjB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O,GAAmB,MAAM;AAAA,EACrD,WAAW,gBAAgB,EAAE,aAAa;AACxC,WAAO,aAAa;AACpB,WAAO,OAAO,KAAK,OAAO,GAAmB,MAAM;AAAA,EACrD,WAAW,gBAAgB,EAAE,aAAa;AACxC,WAAO,aAAa;AACpB,WAAO,OAAO,KAAK,OAAO,GAAmB,MAAM;AAAA,EACrD,WAAW,gBAAgB,EAAE,YAAY;AACvC,WAAO,eAAe,OAAO,KAAK,IAAI,iBAAiB,aACnD,KAAK,IAAI,aAAa,IACtB,KAAK,IAAI;AACb,WAAO,OAAO,KAAK,OAAO,GAAmB,MAAM;AAAA,EACrD,OAAO;AACL,WAAO,CAAC,MAAM,MAAM;AAAA,EACtB;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@mcphero/core",
3
+ "version": "1.1.6",
4
+ "description": "MCP Hero Core",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+ssh://git@github.com/atomicbi/mcphero.git",
8
+ "directory": "packages/core"
9
+ },
10
+ "type": "module",
11
+ "main": "build/index.js",
12
+ "types": "build/index.d.ts",
13
+ "dependencies": {
14
+ "@modelcontextprotocol/sdk": "^1.29.0",
15
+ "zod": "^4.3.6",
16
+ "@mcphero/logger": "1.1.6"
17
+ },
18
+ "devDependencies": {
19
+ "@eslint/js": "^10.0.1",
20
+ "@modelcontextprotocol/inspector": "^0.21.1",
21
+ "@stylistic/eslint-plugin": "^5.10.0",
22
+ "@types/node": "^22.0.0",
23
+ "rimraf": "^6.1.3",
24
+ "tsup": "^8.5.1",
25
+ "tsx": "^4.21.0",
26
+ "typescript": "^5.9.3",
27
+ "typescript-eslint": "^8.56.1"
28
+ },
29
+ "scripts": {
30
+ "clean": "rimraf build",
31
+ "build": "tsup",
32
+ "watch": "tsup --watch",
33
+ "typecheck": "tsc --noEmit",
34
+ "lint": "eslint",
35
+ "check": "pnpm lint && pnpm typecheck"
36
+ }
37
+ }