@pipeworx/mcp-emoji 0.1.1 → 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/README.md +17 -12
- package/bin/cli.js +55 -11
- package/lib/index.js +333 -0
- package/package.json +17 -16
- package/server.json +1 -1
- package/tools.json +38 -0
- package/src/index.ts +0 -121
- package/src/server.ts +0 -45
- package/tsconfig.json +0 -18
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Emoji MCP.
|
|
4
4
|
|
|
5
|
-
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1856+ live data sources. This is an independent, unofficial integration — not affiliated with, endorsed by, or published by the upstream provider.
|
|
6
6
|
|
|
7
7
|
## Tools
|
|
8
8
|
|
|
@@ -55,7 +55,7 @@ directly, instead of just this one's:
|
|
|
55
55
|
}
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
Both URLs reach the same gateway and the same
|
|
58
|
+
Both URLs reach the same gateway and the same 1856+ data sources. The
|
|
59
59
|
only difference is which pack's tools are listed **directly**; `ask_pipeworx`
|
|
60
60
|
reaches all of them from either one.
|
|
61
61
|
|
|
@@ -69,10 +69,12 @@ curl -X POST https://gateway.pipeworx.io/v1/tools/emoji_lookup \
|
|
|
69
69
|
|
|
70
70
|
No account needed for the first calls. Inspect any tool: `GET https://gateway.pipeworx.io/v1/tools/emoji_lookup`. Find one: `POST https://gateway.pipeworx.io/v1/tools/search_packs` with `{"query":"..."}`.
|
|
71
71
|
|
|
72
|
-
##
|
|
72
|
+
## Run it from npm
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
`@pipeworx/mcp-emoji` is a local stdio bridge to the Pipeworx gateway: your MCP client
|
|
75
|
+
starts it with `npx`, and it forwards every call to the same
|
|
76
|
+
`https://gateway.pipeworx.io/emoji/mcp` endpoint shown above. It needs network access;
|
|
77
|
+
there is no offline mode.
|
|
76
78
|
|
|
77
79
|
```json
|
|
78
80
|
{
|
|
@@ -85,15 +87,18 @@ gateway round-trip:
|
|
|
85
87
|
}
|
|
86
88
|
```
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
Without a key it calls anonymously, capped at 50 calls a day. A free account
|
|
91
|
+
raises that to 200 a day: get a key at https://pipeworx.io/signup and add
|
|
92
|
+
`"env": { "PIPEWORX_API_KEY": "<your key>" }` to the server entry.
|
|
93
|
+
The key is sent as a Bearer token, the same way a hosted connection sends it,
|
|
94
|
+
so calls are metered and billed exactly as they are there.
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
```
|
|
96
|
+
It lists **only** this pack's tools by default. Set `PIPEWORX_META_TOOLS=1` to
|
|
97
|
+
also list `ask_pipeworx` and the other gateway-wide tools.
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
Behind an HTTPS proxy: Node's built-in `fetch` does not read `HTTPS_PROXY` by
|
|
100
|
+
default. Newer Node releases honour it when `NODE_USE_ENV_PROXY=1` is set; check
|
|
101
|
+
your Node version's documentation.
|
|
97
102
|
|
|
98
103
|
## Using with ask_pipeworx
|
|
99
104
|
|
package/bin/cli.js
CHANGED
|
@@ -1,17 +1,61 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// Entry point for `npx @pipeworx/mcp-<slug>` in gateway mode (bin/cli.js).
|
|
2
3
|
//
|
|
3
|
-
//
|
|
4
|
+
// A stdio MCP server that relays every message to the Pipeworx gateway's
|
|
5
|
+
// /<slug>/mcp endpoint -- fleet #3759, docs/standalone-via-gateway-plan.md.
|
|
6
|
+
// It carries no pack code and has no local mode. The relay itself lives in
|
|
7
|
+
// ../lib/index.js (copied from scripts/templates/standalone-gateway-lib.js);
|
|
8
|
+
// this file only owns stdin/stdout.
|
|
4
9
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// per-pack
|
|
8
|
-
// registers tsx's ESM loader programmatically, then hands off to src/server.ts,
|
|
9
|
-
// which wraps the pack's {tools, callTool} export in a stdio MCP server.
|
|
10
|
+
// Copied VERBATIM into every gateway-mode package by scripts/publish-pack.sh.
|
|
11
|
+
// Edit scripts/templates/standalone-gateway-cli.js in the monorepo, never a
|
|
12
|
+
// per-pack copy. Zero dependencies, Node 18+.
|
|
10
13
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
+
// stdout carries newline-delimited JSON-RPC and nothing else; every diagnostic
|
|
15
|
+
// goes to stderr, because a single stray line on stdout breaks the host's
|
|
16
|
+
// parser.
|
|
17
|
+
import { createInterface } from 'node:readline';
|
|
18
|
+
import { relay, bridgeConfig } from '../lib/index.js';
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
const cfg = bridgeConfig();
|
|
21
|
+
const warn = (line) => process.stderr.write(`${line}\n`);
|
|
22
|
+
const write = (msg) => { if (msg) process.stdout.write(`${JSON.stringify(msg)}\n`); };
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
const pending = new Set();
|
|
25
|
+
function track(p) {
|
|
26
|
+
pending.add(p);
|
|
27
|
+
p.finally(() => pending.delete(p));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function handleLine(line) {
|
|
31
|
+
const text = line.trim();
|
|
32
|
+
if (!text) return;
|
|
33
|
+
let message;
|
|
34
|
+
try {
|
|
35
|
+
message = JSON.parse(text);
|
|
36
|
+
} catch {
|
|
37
|
+
write({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// A JSON-RPC batch: relay each member, answer with the non-notification replies.
|
|
41
|
+
if (Array.isArray(message)) {
|
|
42
|
+
const replies = (await Promise.all(message.map((m) => relay(m, { cfg, warn })))).filter(Boolean);
|
|
43
|
+
if (replies.length) write(replies);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
write(await relay(message, { cfg, warn }));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Requests are handled concurrently and answered as they finish: JSON-RPC ids
|
|
50
|
+
// let the host match them, and a slow tool call must not hold up a ping.
|
|
51
|
+
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
52
|
+
rl.on('line', (line) => {
|
|
53
|
+
track(handleLine(line).catch((err) => warn(`pipeworx-standalone: ${err && err.stack ? err.stack : err}`)));
|
|
54
|
+
});
|
|
55
|
+
rl.on('close', async () => {
|
|
56
|
+
// stdin closed: finish what is in flight, then exit.
|
|
57
|
+
while (pending.size) await Promise.allSettled([...pending]);
|
|
58
|
+
// Exit only once stdout has flushed: on a pipe that is not synchronous
|
|
59
|
+
// everywhere, and a bare exit can drop the last reply.
|
|
60
|
+
process.stdout.write('', () => process.exit(0));
|
|
61
|
+
});
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// @pipeworx/mcp-<slug> -- library half of the gateway bridge (lib/index.js).
|
|
2
|
+
//
|
|
3
|
+
// Copied VERBATIM into every gateway-mode pack package by scripts/publish-pack.sh
|
|
4
|
+
// (fleet #3759, docs/standalone-via-gateway-plan.md section 1). There is no
|
|
5
|
+
// per-pack templating: the slug and version are read from this package's own
|
|
6
|
+
// package.json (`pipeworx.slug`, `version`) at load time, so the same bytes
|
|
7
|
+
// ship in every package and the source hash can cover them once. Edit this
|
|
8
|
+
// file in the monorepo (scripts/templates/standalone-gateway-lib.js), never a
|
|
9
|
+
// per-pack copy.
|
|
10
|
+
//
|
|
11
|
+
// What it is: a relay. Every JSON-RPC message goes to
|
|
12
|
+
// ${PIPEWORX_GATEWAY_URL:-https://gateway.pipeworx.io}/<slug>/mcp, the same
|
|
13
|
+
// endpoint a hosted MCP client uses, so tiers, rate limits and credits apply
|
|
14
|
+
// exactly as they do there. There is no local mode: the pack's code is not in
|
|
15
|
+
// this package.
|
|
16
|
+
//
|
|
17
|
+
// Zero dependencies, plain ESM, Node 18+ (global fetch). Nothing here writes
|
|
18
|
+
// to stdout -- bin/cli.js owns stdout and it carries JSON-RPC only.
|
|
19
|
+
//
|
|
20
|
+
// Environment:
|
|
21
|
+
// PIPEWORX_API_KEY sent as `Authorization: Bearer <key>`. Never as
|
|
22
|
+
// X-API-Key: the gateway reads a pwx_ key sent that way
|
|
23
|
+
// as an unvalidated BYO string with no account.
|
|
24
|
+
// PIPEWORX_GATEWAY_URL gateway base URL (no path), default the public gateway.
|
|
25
|
+
// PIPEWORX_META_TOOLS=1 list the gateway-wide tools (ask_pipeworx, ...) too.
|
|
26
|
+
// PIPEWORX_TIMEOUT_MS per-request timeout, default 120000.
|
|
27
|
+
|
|
28
|
+
import { readFileSync } from 'node:fs';
|
|
29
|
+
|
|
30
|
+
const readJson = (rel) => JSON.parse(readFileSync(new URL(rel, import.meta.url), 'utf8'));
|
|
31
|
+
|
|
32
|
+
const PKG = readJson('../package.json');
|
|
33
|
+
export const SLUG = PKG.pipeworx && PKG.pipeworx.slug;
|
|
34
|
+
if (typeof SLUG !== 'string' || !/^[a-z0-9][a-z0-9_-]*$/.test(SLUG)) {
|
|
35
|
+
throw new Error(`${PKG.name}: package.json carries no valid pipeworx.slug -- this package was built wrong`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The pack's slug on the GATEWAY: the /<slug>/mcp route and the `_meta.pack`
|
|
39
|
+
* every listed tool carries. Usually the same as `slug` (the npm/directory
|
|
40
|
+
* name), but 14 packs differ -- `hex-pm` is `hex_pm` on the gateway -- and
|
|
41
|
+
* filtering tools/list on the npm slug would match none of their tools
|
|
42
|
+
* (fleet #3761). publish-pack.sh stamps it from the gateway manifest.
|
|
43
|
+
*/
|
|
44
|
+
export const GATEWAY_SLUG = (PKG.pipeworx && PKG.pipeworx.gatewaySlug) || SLUG;
|
|
45
|
+
if (typeof GATEWAY_SLUG !== 'string' || !/^[a-z0-9][a-z0-9_-]*$/.test(GATEWAY_SLUG)) {
|
|
46
|
+
throw new Error(`${PKG.name}: package.json carries an invalid pipeworx.gatewaySlug -- this package was built wrong`);
|
|
47
|
+
}
|
|
48
|
+
export const PACKAGE_NAME = PKG.name;
|
|
49
|
+
export const VERSION = PKG.version;
|
|
50
|
+
|
|
51
|
+
/** The pack's own tool definitions at publish time (the offline tools/list answer). */
|
|
52
|
+
export const tools = readJson('../tools.json');
|
|
53
|
+
|
|
54
|
+
const DEFAULT_GATEWAY = 'https://gateway.pipeworx.io';
|
|
55
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
56
|
+
const SIGNUP_URL = 'https://pipeworx.io/signup';
|
|
57
|
+
const VIA = '(via pipeworx-standalone)';
|
|
58
|
+
|
|
59
|
+
/** Resolve the bridge's settings. Exported for the tests and for callTool. */
|
|
60
|
+
export function bridgeConfig(env = process.env, overrides = {}) {
|
|
61
|
+
const base = String(overrides.gatewayUrl || env.PIPEWORX_GATEWAY_URL || DEFAULT_GATEWAY).trim().replace(/\/+$/, '');
|
|
62
|
+
const apiKey = String(overrides.apiKey ?? env.PIPEWORX_API_KEY ?? '').trim();
|
|
63
|
+
const t = Number(overrides.timeoutMs ?? env.PIPEWORX_TIMEOUT_MS);
|
|
64
|
+
return {
|
|
65
|
+
endpoint: `${base}/${GATEWAY_SLUG}/mcp`,
|
|
66
|
+
apiKey,
|
|
67
|
+
timeoutMs: Number.isFinite(t) && t > 0 ? t : DEFAULT_TIMEOUT_MS,
|
|
68
|
+
metaTools: (overrides.metaTools ?? env.PIPEWORX_META_TOOLS) === '1' || overrides.metaTools === true,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function requestHeaders(cfg) {
|
|
73
|
+
const h = {
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
Accept: 'application/json',
|
|
76
|
+
// Stable per package version: the gateway remembers a client's name by
|
|
77
|
+
// identifier + User-Agent (workers/gateway/src/client-identity.ts).
|
|
78
|
+
'User-Agent': `pipeworx-standalone/${VERSION} (${PACKAGE_NAME})`,
|
|
79
|
+
// Analytics label only (blob11 = 'standalone'). It never changes tier,
|
|
80
|
+
// limits or price -- anyone can send it.
|
|
81
|
+
'X-Pipeworx-Surface': 'standalone',
|
|
82
|
+
};
|
|
83
|
+
if (cfg.apiKey) h.Authorization = `Bearer ${cfg.apiKey}`;
|
|
84
|
+
return h;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Parse a gateway body: JSON, or the last JSON `data:` frame of an SSE stream. */
|
|
88
|
+
function parseBody(text, contentType) {
|
|
89
|
+
if (/text\/event-stream/i.test(contentType || '')) {
|
|
90
|
+
let last = null;
|
|
91
|
+
for (const line of text.split(/\r?\n/)) {
|
|
92
|
+
if (!line.startsWith('data:')) continue;
|
|
93
|
+
try { last = JSON.parse(line.slice(5).trim()); } catch { /* keep-alive or partial frame */ }
|
|
94
|
+
}
|
|
95
|
+
return last;
|
|
96
|
+
}
|
|
97
|
+
try { return JSON.parse(text); } catch { return null; }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* POST one JSON-RPC message. Never throws: the outcome is one of
|
|
102
|
+
* { kind: 'http', status, headers, body, text } the gateway answered
|
|
103
|
+
* { kind: 'network', detail } DNS, TLS, refused, reset
|
|
104
|
+
* { kind: 'timeout' } no answer in cfg.timeoutMs
|
|
105
|
+
*/
|
|
106
|
+
export async function postToGateway(message, cfg) {
|
|
107
|
+
const ac = new AbortController();
|
|
108
|
+
const timer = setTimeout(() => ac.abort(), cfg.timeoutMs);
|
|
109
|
+
try {
|
|
110
|
+
const res = await fetch(cfg.endpoint, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: requestHeaders(cfg),
|
|
113
|
+
body: JSON.stringify(message),
|
|
114
|
+
signal: ac.signal,
|
|
115
|
+
});
|
|
116
|
+
const text = await res.text();
|
|
117
|
+
return { kind: 'http', status: res.status, headers: res.headers, body: parseBody(text, res.headers.get('content-type')), text };
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (ac.signal.aborted || (err && (err.name === 'AbortError' || err.name === 'TimeoutError'))) return { kind: 'timeout' };
|
|
120
|
+
const cause = err && err.cause;
|
|
121
|
+
const detail = (cause && (cause.code || cause.message)) || (err && err.message) || String(err);
|
|
122
|
+
return { kind: 'network', detail };
|
|
123
|
+
} finally {
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ── The key-not-accepted warning (one per process) ──────────────────
|
|
129
|
+
|
|
130
|
+
let warnedKeyIgnored = false;
|
|
131
|
+
const KEY_IGNORED = 'PIPEWORX_API_KEY was not accepted, calling anonymously.';
|
|
132
|
+
|
|
133
|
+
/** True when a key was sent but the gateway still served the call as anonymous. */
|
|
134
|
+
function keyIgnored(out, cfg) {
|
|
135
|
+
return !!cfg.apiKey && out.kind === 'http' && (out.headers.get('x-ratelimit-tier') || '').toLowerCase() === 'anonymous';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function noteTier(out, cfg, warn) {
|
|
139
|
+
if (!keyIgnored(out, cfg) || warnedKeyIgnored) return;
|
|
140
|
+
warnedKeyIgnored = true;
|
|
141
|
+
warn(`${PACKAGE_NAME}: ${KEY_IGNORED} Check the key at ${SIGNUP_URL}.`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Test hook: forget that the warning was printed. */
|
|
145
|
+
export function _resetWarnings() { warnedKeyIgnored = false; }
|
|
146
|
+
|
|
147
|
+
// ── Results the host shows to the model ─────────────────────────────
|
|
148
|
+
|
|
149
|
+
function errorResult(text, detail) {
|
|
150
|
+
const result = { content: [{ type: 'text', text }], isError: true };
|
|
151
|
+
if (detail) result._meta = { pipeworx_standalone: detail };
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const rpcResult = (id, result) => ({ jsonrpc: '2.0', id, result });
|
|
156
|
+
const rpcError = (id, code, message) => ({ jsonrpc: '2.0', id, error: { code, message } });
|
|
157
|
+
|
|
158
|
+
function firstLine(text) {
|
|
159
|
+
const line = String(text || '').split(/\r?\n/).map((l) => l.trim()).find(Boolean) || '(empty body)';
|
|
160
|
+
return line.length > 200 ? `${line.slice(0, 200)}...` : line;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function unreachableText(cfg, out) {
|
|
164
|
+
if (out.kind === 'timeout') {
|
|
165
|
+
return `The Pipeworx gateway at ${cfg.endpoint} did not answer within ${Math.round(cfg.timeoutMs / 1000)}s, so this call timed out. `
|
|
166
|
+
+ `${PACKAGE_NAME} forwards every call to the Pipeworx gateway and has no local mode. Try again; a call that keeps timing out is worth reporting.`;
|
|
167
|
+
}
|
|
168
|
+
return `Could not reach the Pipeworx gateway at ${cfg.endpoint} (${out.detail}). `
|
|
169
|
+
+ `${PACKAGE_NAME} forwards every call to the Pipeworx gateway and has no local mode, so it needs network access.`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function isAuthRequired(body) {
|
|
173
|
+
return !!body && (body.error_code === 'authentication_required'
|
|
174
|
+
|| (body.error && body.error.data && body.error.data.reason === 'authentication_required'));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Map a tools/call outcome to the JSON-RPC response the host gets. */
|
|
178
|
+
function toolsCallResponse(id, out, cfg) {
|
|
179
|
+
if (out.kind !== 'http') return rpcResult(id, errorResult(unreachableText(cfg, out), { reason: out.kind }));
|
|
180
|
+
const { status, body } = out;
|
|
181
|
+
|
|
182
|
+
// Anonymous daily cap: the gateway answers 401 with a JSON-RPC error whose
|
|
183
|
+
// message is the offer. Hosts often swallow protocol errors, so hand it over
|
|
184
|
+
// as a tool result the model actually reads.
|
|
185
|
+
if (status === 401 && isAuthRequired(body)) {
|
|
186
|
+
const data = (body.error && body.error.data) || {};
|
|
187
|
+
const parts = [body.error && body.error.message ? body.error.message : 'The anonymous daily allowance is used up.'];
|
|
188
|
+
if (data.resets_at) parts.push(`The anonymous allowance resets at ${data.resets_at}.`);
|
|
189
|
+
parts.push(cfg.apiKey
|
|
190
|
+
? `${KEY_IGNORED} Check the key, or get a free one at ${SIGNUP_URL}.`
|
|
191
|
+
: `To keep going now, set PIPEWORX_API_KEY in this MCP server's environment; a free key is at ${SIGNUP_URL}.`);
|
|
192
|
+
return rpcResult(id, errorResult(parts.join('\n\n'), { status, reason: 'authentication_required', resets_at: data.resets_at ?? null }));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// A keyed tier over its cap: today the gateway answers 429 with a RESULT
|
|
196
|
+
// that has no isError, which reads as a success (fleet #3760). Mark it.
|
|
197
|
+
if (status === 429 && body && body.result && typeof body.result === 'object') {
|
|
198
|
+
const result = { ...body.result, isError: true };
|
|
199
|
+
if (cfg.apiKey && keyIgnored(out, cfg)) {
|
|
200
|
+
result.content = [...(Array.isArray(result.content) ? result.content : []), { type: 'text', text: KEY_IGNORED }];
|
|
201
|
+
}
|
|
202
|
+
return rpcResult(id, result);
|
|
203
|
+
}
|
|
204
|
+
if ((status === 401 || status === 429) && body && body.error) {
|
|
205
|
+
const extra = keyIgnored(out, cfg) ? ` ${KEY_IGNORED}` : '';
|
|
206
|
+
return rpcResult(id, errorResult(`${body.error.message || `HTTP ${status}`}${extra}`, { status }));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// A real JSON-RPC answer (result or protocol error): relay it verbatim,
|
|
210
|
+
// structuredContent and _meta (cost, tier, provenance) included.
|
|
211
|
+
if (body && body.jsonrpc === '2.0' && (body.result !== undefined || body.error !== undefined) && status < 500) {
|
|
212
|
+
return { ...body, id };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 5xx, an HTML edge page, or anything else that is not JSON-RPC.
|
|
216
|
+
return rpcResult(id, errorResult(`The Pipeworx gateway returned HTTP ${status}: ${firstLine(out.text)}`, { status }));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function localInitialize(params) {
|
|
220
|
+
return {
|
|
221
|
+
protocolVersion: (params && params.protocolVersion) || '2025-06-18',
|
|
222
|
+
capabilities: { tools: {} },
|
|
223
|
+
serverInfo: { name: PACKAGE_NAME, version: VERSION },
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const scopedInstructions = () =>
|
|
228
|
+
`${PACKAGE_NAME} forwards to the Pipeworx gateway and lists only the ${SLUG} pack's tools. `
|
|
229
|
+
+ 'Set PIPEWORX_META_TOOLS=1 to also list ask_pipeworx and the other gateway-wide tools.';
|
|
230
|
+
|
|
231
|
+
/** `<host name> (via pipeworx-standalone)`. The slug stays OUT of the name: the
|
|
232
|
+
* gateway's scanner-name check substring-matches words like poll/watch/index. */
|
|
233
|
+
export function bridgedClientName(name) {
|
|
234
|
+
const n = typeof name === 'string' && name.trim() ? name.trim() : 'unknown';
|
|
235
|
+
return n.includes(VIA) ? n : `${n} ${VIA}`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Relay one JSON-RPC message to the gateway and return the response to write
|
|
240
|
+
* back, or null for a notification. Never throws.
|
|
241
|
+
*
|
|
242
|
+
* @param {object} message a parsed JSON-RPC request or notification
|
|
243
|
+
* @param {{cfg?: object, warn?: (line: string) => void}} [opts]
|
|
244
|
+
*/
|
|
245
|
+
export async function relay(message, opts = {}) {
|
|
246
|
+
const cfg = opts.cfg || bridgeConfig();
|
|
247
|
+
const warn = opts.warn || ((line) => process.stderr.write(`${line}\n`));
|
|
248
|
+
if (!message || typeof message !== 'object' || message.jsonrpc !== '2.0' || typeof message.method !== 'string') {
|
|
249
|
+
const id = message && typeof message === 'object' && 'id' in message ? message.id : null;
|
|
250
|
+
return rpcError(id ?? null, -32600, 'Invalid Request');
|
|
251
|
+
}
|
|
252
|
+
const isNotification = !('id' in message) || message.id === undefined;
|
|
253
|
+
const id = message.id;
|
|
254
|
+
|
|
255
|
+
if (isNotification) {
|
|
256
|
+
const out = await postToGateway(message, cfg);
|
|
257
|
+
if (out.kind !== 'http') warn(`${PACKAGE_NAME}: notification ${message.method} not delivered: ${unreachableText(cfg, out)}`);
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (message.method === 'initialize') {
|
|
262
|
+
const params = { ...(message.params || {}) };
|
|
263
|
+
params.clientInfo = { ...(params.clientInfo || {}), name: bridgedClientName(params.clientInfo && params.clientInfo.name) };
|
|
264
|
+
if (!params.clientInfo.version) params.clientInfo.version = '0';
|
|
265
|
+
const out = await postToGateway({ ...message, params }, cfg);
|
|
266
|
+
noteTier(out, cfg, warn);
|
|
267
|
+
if (out.kind === 'http' && out.body && out.body.result && typeof out.body.result === 'object') {
|
|
268
|
+
const result = { ...out.body.result, serverInfo: { name: PACKAGE_NAME, version: VERSION } };
|
|
269
|
+
if (!cfg.metaTools) result.instructions = scopedInstructions();
|
|
270
|
+
return rpcResult(id, result);
|
|
271
|
+
}
|
|
272
|
+
// The host must still start: answer locally and let the calls report the
|
|
273
|
+
// gateway problem when they happen.
|
|
274
|
+
warn(`${PACKAGE_NAME}: initialize answered locally -- ${out.kind === 'http' ? `gateway HTTP ${out.status}` : unreachableText(cfg, out)}`);
|
|
275
|
+
return rpcResult(id, { ...localInitialize(message.params), instructions: scopedInstructions() });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (message.method === 'tools/list') {
|
|
279
|
+
const out = await postToGateway(message, cfg);
|
|
280
|
+
noteTier(out, cfg, warn);
|
|
281
|
+
const listed = out.kind === 'http' && out.body && out.body.result && Array.isArray(out.body.result.tools)
|
|
282
|
+
? out.body.result : null;
|
|
283
|
+
if (listed) {
|
|
284
|
+
if (cfg.metaTools) return rpcResult(id, listed);
|
|
285
|
+
const own = listed.tools.filter((t) => t && t._meta && (t._meta.pack === GATEWAY_SLUG || t._meta.pack === SLUG));
|
|
286
|
+
if (own.length > 0) return rpcResult(id, { ...listed, tools: own });
|
|
287
|
+
warn(`${PACKAGE_NAME}: the gateway listed no ${SLUG} tools; serving the tool list bundled with this package`);
|
|
288
|
+
} else {
|
|
289
|
+
warn(`${PACKAGE_NAME}: tools/list served from the snapshot bundled with this package -- ${out.kind === 'http' ? `gateway HTTP ${out.status}` : unreachableText(cfg, out)}`);
|
|
290
|
+
}
|
|
291
|
+
return rpcResult(id, { tools });
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (message.method === 'tools/call') {
|
|
295
|
+
const out = await postToGateway(message, cfg);
|
|
296
|
+
noteTier(out, cfg, warn);
|
|
297
|
+
return toolsCallResponse(id, out, cfg);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Everything else (ping, resources/*, prompts/*, ...): relay as-is.
|
|
301
|
+
const out = await postToGateway(message, cfg);
|
|
302
|
+
noteTier(out, cfg, warn);
|
|
303
|
+
if (out.kind === 'http' && out.body && out.body.jsonrpc === '2.0') return { ...out.body, id };
|
|
304
|
+
if (message.method === 'ping') return rpcResult(id, {});
|
|
305
|
+
return rpcError(id, -32603, out.kind === 'http'
|
|
306
|
+
? `The Pipeworx gateway returned HTTP ${out.status}: ${firstLine(out.text)}`
|
|
307
|
+
: unreachableText(cfg, out));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Call one of this pack's tools through the gateway -- the `{tools, callTool}`
|
|
312
|
+
* shape earlier versions of this package exported. Resolves with the tool's
|
|
313
|
+
* structured result; rejects with the gateway's message on any error.
|
|
314
|
+
*
|
|
315
|
+
* @param {string} name
|
|
316
|
+
* @param {Record<string, unknown>} [args]
|
|
317
|
+
* @param {{apiKey?: string, gatewayUrl?: string, timeoutMs?: number}} [opts]
|
|
318
|
+
* apiKey defaults to process.env.PIPEWORX_API_KEY.
|
|
319
|
+
*/
|
|
320
|
+
export async function callTool(name, args = {}, opts = {}) {
|
|
321
|
+
const cfg = bridgeConfig(process.env, opts);
|
|
322
|
+
const res = await relay({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: args } }, { cfg });
|
|
323
|
+
if (res.error) throw new Error(res.error.message);
|
|
324
|
+
const result = res.result || {};
|
|
325
|
+
const text = Array.isArray(result.content)
|
|
326
|
+
? result.content.filter((c) => c && c.type === 'text').map((c) => c.text).join('\n')
|
|
327
|
+
: '';
|
|
328
|
+
if (result.isError) throw new Error(text || `${name} failed`);
|
|
329
|
+
if (result.structuredContent !== undefined) return result.structuredContent;
|
|
330
|
+
try { return JSON.parse(text); } catch { return text; }
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export default { tools, callTool };
|
package/package.json
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipeworx/mcp-emoji",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Emoji MCP.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "
|
|
7
|
-
"
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/index.js",
|
|
9
|
+
"./tools.json": "./tools.json",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
8
12
|
"bin": {
|
|
9
13
|
"mcp-emoji": "bin/cli.js"
|
|
10
14
|
},
|
|
15
|
+
"files": ["bin/", "lib/", "tools.json", "server.json"],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
11
19
|
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "emoji"],
|
|
12
20
|
"license": "MIT",
|
|
13
21
|
"repository": {
|
|
14
22
|
"type": "git",
|
|
15
23
|
"url": "git+https://github.com/pipeworx-io/mcp-emoji.git"
|
|
16
24
|
},
|
|
17
|
-
"
|
|
18
|
-
"typecheck": "tsc --noEmit"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
22
|
-
"tsx": "^4.19.0"
|
|
23
|
-
},
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"typescript": "^5.9.3",
|
|
26
|
-
"@cloudflare/workers-types": "^4.20260405.1"
|
|
27
|
-
},
|
|
25
|
+
"mcpName": "io.github.pipeworx-io/emoji",
|
|
28
26
|
"pipeworx": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
27
|
+
"mode": "gateway",
|
|
28
|
+
"slug": "emoji",
|
|
29
|
+
"gatewaySlug": "emoji",
|
|
30
|
+
"sourceHash": "v1-2508389de204072b689bde2c2a05b8e56789055403152c57556869a7a00f2046",
|
|
31
|
+
"sourceCommit": "bb047243cf27f32453103de186b8e6a8b6a1ce79"
|
|
31
32
|
}
|
|
32
33
|
}
|
package/server.json
CHANGED
package/tools.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "emoji_lookup",
|
|
4
|
+
"description": "Look up an emoji by :shortcode: (e.g. \":fire:\" or \"fire\") to get the character + keywords, OR pass an emoji character to get its shortcode/name. Keyless, offline.",
|
|
5
|
+
"inputSchema": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"input": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "A :shortcode:, a bare shortcode, or an emoji character."
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"required": [
|
|
14
|
+
"input"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "search_emoji",
|
|
20
|
+
"description": "Search emoji by keyword/name (e.g. \"party\", \"money\", \"animal\") and return matching emoji with shortcodes. Keyless, offline.",
|
|
21
|
+
"inputSchema": {
|
|
22
|
+
"type": "object",
|
|
23
|
+
"properties": {
|
|
24
|
+
"query": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "A keyword to search."
|
|
27
|
+
},
|
|
28
|
+
"limit": {
|
|
29
|
+
"type": "number",
|
|
30
|
+
"description": "Max results (default 20)."
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"required": [
|
|
34
|
+
"query"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
package/src/index.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
interface McpToolDefinition {
|
|
2
|
-
name: string;
|
|
3
|
-
description: string;
|
|
4
|
-
/** Human-facing one-liner (fleet #1967). Optional; consumers fall back to
|
|
5
|
-
* description. Kept in step with shared/src/types.ts — scripts/lib/
|
|
6
|
-
* check-inlined-types.mjs reports drift at publish time. */
|
|
7
|
-
summary?: string;
|
|
8
|
-
inputSchema: {
|
|
9
|
-
type: 'object';
|
|
10
|
-
properties: Record<string, unknown>;
|
|
11
|
-
required?: string[];
|
|
12
|
-
anyOf?: Array<{ required: string[] }>;
|
|
13
|
-
oneOf?: Array<{ required: string[] }>;
|
|
14
|
-
allOf?: Array<{ required: string[] }>;
|
|
15
|
-
};
|
|
16
|
-
outputSchema?: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface McpToolExport {
|
|
20
|
-
tools: McpToolDefinition[];
|
|
21
|
-
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
22
|
-
meter?: { credits: number };
|
|
23
|
-
cost?: Record<string, unknown>;
|
|
24
|
-
provider?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Emoji MCP.
|
|
29
|
-
*
|
|
30
|
-
* Keyless, offline: look up an emoji by :shortcode: (or reverse — get the
|
|
31
|
-
* shortcode/name for an emoji character) and search emoji by keyword, from an
|
|
32
|
-
* inlined table of common emoji. Pure lookup — no API, no key.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// [emoji, shortcode, keywords]
|
|
37
|
-
const DATA: [string, string, string][] = [
|
|
38
|
-
['😀', 'grinning', 'happy smile face'], ['😃', 'smiley', 'happy joy'], ['😄', 'smile', 'happy laugh'],
|
|
39
|
-
['😁', 'grin', 'happy'], ['😂', 'joy', 'laugh cry tears funny'], ['🤣', 'rofl', 'laugh rolling funny'],
|
|
40
|
-
['🙂', 'slightly_smiling_face', 'smile'], ['😉', 'wink', 'flirt'], ['😊', 'blush', 'happy smile'],
|
|
41
|
-
['😍', 'heart_eyes', 'love like'], ['😘', 'kissing_heart', 'kiss love'], ['😎', 'sunglasses', 'cool'],
|
|
42
|
-
['🤔', 'thinking', 'think hmm consider'], ['😐', 'neutral_face', 'meh'], ['🙄', 'roll_eyes', 'annoyed'],
|
|
43
|
-
['😴', 'sleeping', 'sleep tired zzz'], ['😭', 'sob', 'cry sad tears'], ['😢', 'cry', 'sad tear'],
|
|
44
|
-
['😅', 'sweat_smile', 'relief nervous'], ['😤', 'triumph', 'angry proud'], ['😡', 'rage', 'angry mad'],
|
|
45
|
-
['🥳', 'partying_face', 'party celebrate'], ['🤯', 'exploding_head', 'mind blown shock'], ['😱', 'scream', 'fear shock'],
|
|
46
|
-
['🤗', 'hugs', 'hug'], ['🤩', 'star_struck', 'excited amazed'], ['😇', 'innocent', 'angel'],
|
|
47
|
-
['👍', 'thumbsup', 'yes good approve like'], ['👎', 'thumbsdown', 'no bad dislike'], ['👏', 'clap', 'applause bravo'],
|
|
48
|
-
['🙏', 'pray', 'please thanks hope'], ['🙌', 'raised_hands', 'celebrate praise'], ['👋', 'wave', 'hello bye hi'],
|
|
49
|
-
['🤝', 'handshake', 'deal agree'], ['✌️', 'v', 'peace victory'], ['🤞', 'crossed_fingers', 'luck hope'],
|
|
50
|
-
['💪', 'muscle', 'strong flex gym'], ['👀', 'eyes', 'look see watch'], ['🧠', 'brain', 'smart think'],
|
|
51
|
-
['❤️', 'heart', 'love red'], ['🧡', 'orange_heart', 'love'], ['💛', 'yellow_heart', 'love'],
|
|
52
|
-
['💚', 'green_heart', 'love'], ['💙', 'blue_heart', 'love'], ['💜', 'purple_heart', 'love'],
|
|
53
|
-
['🖤', 'black_heart', 'love'], ['💔', 'broken_heart', 'sad heartbreak'], ['💯', '100', 'perfect score keep it'],
|
|
54
|
-
['🔥', 'fire', 'lit hot flame'], ['✨', 'sparkles', 'shine magic new'], ['⭐', 'star', 'favorite'],
|
|
55
|
-
['🎉', 'tada', 'party celebrate congrats'], ['🎊', 'confetti_ball', 'party celebrate'], ['🎈', 'balloon', 'party'],
|
|
56
|
-
['🚀', 'rocket', 'launch ship fast space'], ['💡', 'bulb', 'idea light'], ['⚡', 'zap', 'lightning fast power'],
|
|
57
|
-
['💰', 'moneybag', 'money cash rich'], ['💸', 'money_with_wings', 'spend money'], ['💵', 'dollar', 'money cash'],
|
|
58
|
-
['📈', 'chart_with_upwards_trend', 'growth up stocks'], ['📉', 'chart_with_downwards_trend', 'down loss'],
|
|
59
|
-
['✅', 'white_check_mark', 'yes done correct ok'], ['❌', 'x', 'no wrong cancel'], ['⚠️', 'warning', 'caution alert'],
|
|
60
|
-
['❓', 'question', 'help ask'], ['❗', 'exclamation', 'important'], ['🔔', 'bell', 'notification alert'],
|
|
61
|
-
['🔒', 'lock', 'secure private'], ['🔑', 'key', 'password access'], ['🛠️', 'hammer_and_wrench', 'tools fix build'],
|
|
62
|
-
['🐶', 'dog', 'puppy pet'], ['🐱', 'cat', 'kitten pet'], ['🦊', 'fox', 'animal'], ['🐻', 'bear', 'animal'],
|
|
63
|
-
['🦁', 'lion', 'animal'], ['🐸', 'frog', 'animal'], ['🐢', 'turtle', 'slow animal'], ['🦄', 'unicorn', 'magic'],
|
|
64
|
-
['🐝', 'bee', 'insect'], ['🦋', 'butterfly', 'insect'], ['🌍', 'earth_africa', 'world globe planet'],
|
|
65
|
-
['🌙', 'crescent_moon', 'night'], ['☀️', 'sunny', 'sun weather'], ['☁️', 'cloud', 'weather'],
|
|
66
|
-
['🌧️', 'rain_cloud', 'rain weather'], ['❄️', 'snowflake', 'snow cold winter'], ['🌈', 'rainbow', 'pride color'],
|
|
67
|
-
['🍕', 'pizza', 'food'], ['🍔', 'hamburger', 'food burger'], ['🌮', 'taco', 'food'], ['🍣', 'sushi', 'food'],
|
|
68
|
-
['☕', 'coffee', 'drink caffeine'], ['🍺', 'beer', 'drink'], ['🍷', 'wine_glass', 'drink'], ['🎂', 'birthday', 'cake party'],
|
|
69
|
-
['🍎', 'apple', 'fruit food'], ['🥑', 'avocado', 'food'], ['⚽', 'soccer', 'football sport'], ['🏀', 'basketball', 'sport'],
|
|
70
|
-
['🎮', 'video_game', 'gaming play'], ['🎵', 'musical_note', 'music song'], ['📱', 'iphone', 'phone mobile'],
|
|
71
|
-
['💻', 'computer', 'laptop code'], ['⌨️', 'keyboard', 'type code'], ['📧', 'email', 'mail message'],
|
|
72
|
-
['📌', 'pushpin', 'pin location'], ['📎', 'paperclip', 'attach'], ['🔗', 'link', 'url chain'],
|
|
73
|
-
['🎯', 'dart', 'target goal bullseye'], ['🏆', 'trophy', 'win award champion'], ['🥇', 'first_place_medal', 'gold win'],
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
const byShort = new Map<string, [string, string, string]>();
|
|
77
|
-
const byEmoji = new Map<string, [string, string, string]>();
|
|
78
|
-
for (const d of DATA) { byShort.set(d[1], d); byEmoji.set(d[0], d); }
|
|
79
|
-
|
|
80
|
-
const tools: McpToolExport['tools'] = [
|
|
81
|
-
{
|
|
82
|
-
name: 'emoji_lookup',
|
|
83
|
-
description: 'Look up an emoji by :shortcode: (e.g. ":fire:" or "fire") to get the character + keywords, OR pass an emoji character to get its shortcode/name. Keyless, offline.',
|
|
84
|
-
inputSchema: { type: 'object', properties: { input: { type: 'string', description: 'A :shortcode:, a bare shortcode, or an emoji character.' } }, required: ['input'] },
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: 'search_emoji',
|
|
88
|
-
description: 'Search emoji by keyword/name (e.g. "party", "money", "animal") and return matching emoji with shortcodes. Keyless, offline.',
|
|
89
|
-
inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'A keyword to search.' }, limit: { type: 'number', description: 'Max results (default 20).' } }, required: ['query'] },
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
94
|
-
switch (name) {
|
|
95
|
-
case 'emoji_lookup': {
|
|
96
|
-
const input = reqStr(args, 'input', '":fire:"').trim();
|
|
97
|
-
const short = input.replace(/^:|:$/g, '');
|
|
98
|
-
const byS = byShort.get(short.toLowerCase());
|
|
99
|
-
if (byS) return { input, found: true, emoji: byS[0], shortcode: byS[1], keywords: byS[2].split(' ') };
|
|
100
|
-
const byE = byEmoji.get(input) ?? byEmoji.get([...input][0]);
|
|
101
|
-
if (byE) return { input, found: true, emoji: byE[0], shortcode: byE[1], keywords: byE[2].split(' ') };
|
|
102
|
-
return { input, found: false, reason: 'Not in the emoji table. Try search_emoji by keyword.' };
|
|
103
|
-
}
|
|
104
|
-
case 'search_emoji': {
|
|
105
|
-
const q = reqStr(args, 'query', '"party"').toLowerCase();
|
|
106
|
-
const limit = Math.max(1, Math.min(100, typeof args.limit === 'number' ? args.limit : 20));
|
|
107
|
-
const hits = DATA.filter(([, s, k]) => s.includes(q) || k.includes(q)).slice(0, limit).map(([e, s, k]) => ({ emoji: e, shortcode: s, keywords: k.split(' ') }));
|
|
108
|
-
return { query: q, count: hits.length, results: hits };
|
|
109
|
-
}
|
|
110
|
-
default:
|
|
111
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function reqStr(args: Record<string, unknown>, key: string, ex: string): string {
|
|
116
|
-
const v = args[key];
|
|
117
|
-
if (typeof v !== 'string' || !v.trim()) throw new Error(`Required argument "${key}" is missing. Pass a string like ${ex}.`);
|
|
118
|
-
return v;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
|
package/src/server.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stdio MCP server entry point for @pipeworx/mcp-emoji.
|
|
3
|
-
* Generated by scripts/publish-pack.sh — do not hand-edit in the pack repo;
|
|
4
|
-
* edit scripts/publish-pack.sh (the server.ts heredoc) and republish instead.
|
|
5
|
-
*/
|
|
6
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
|
-
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
-
import pack from './index.js';
|
|
10
|
-
|
|
11
|
-
const server = new Server(
|
|
12
|
-
{ name: '@pipeworx/mcp-emoji', version: '0.1.1' },
|
|
13
|
-
{ capabilities: { tools: {} } },
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
17
|
-
tools: pack.tools.map((t) => ({
|
|
18
|
-
name: t.name,
|
|
19
|
-
description: t.description,
|
|
20
|
-
inputSchema: t.inputSchema,
|
|
21
|
-
})),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
25
|
-
const { name, arguments: args } = request.params;
|
|
26
|
-
try {
|
|
27
|
-
const result = await pack.callTool(name, (args ?? {}) as Record<string, unknown>);
|
|
28
|
-
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
29
|
-
} catch (err) {
|
|
30
|
-
return {
|
|
31
|
-
content: [{ type: 'text', text: err instanceof Error ? err.message : String(err) }],
|
|
32
|
-
isError: true,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
async function main() {
|
|
38
|
-
const transport = new StdioServerTransport();
|
|
39
|
-
await server.connect(transport);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
main().catch((err) => {
|
|
43
|
-
console.error('Fatal error running server:', err);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"lib": ["ES2022"],
|
|
7
|
-
"types": ["@cloudflare/workers-types"],
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"resolveJsonModule": true,
|
|
12
|
-
"outDir": "dist",
|
|
13
|
-
"rootDir": "src",
|
|
14
|
-
"declaration": true
|
|
15
|
-
},
|
|
16
|
-
"include": ["src"],
|
|
17
|
-
"exclude": ["src/server.ts"]
|
|
18
|
-
}
|