norc-mcp 0.3.0 → 0.3.1
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 +4 -0
- package/dist/handler.js +56 -0
- package/dist/server.js +4 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,10 @@ claude mcp add norc --env NORC_API_KEY=norc_sk_... -- npx -y norc-mcp
|
|
|
46
46
|
|
|
47
47
|
Use the same `command` / `args` / `env` block as the Claude Desktop config above. Without `NORC_API_KEY` (or `--stdio`) the server starts in HTTP mode instead, and a missing or malformed key in stdio mode exits with an error.
|
|
48
48
|
|
|
49
|
+
### Hosted (remote clients)
|
|
50
|
+
|
|
51
|
+
For clients that only support remote servers, use `https://mcp.norc.app/mcp` (Streamable HTTP, `POST`) with the header `Authorization: Bearer norc_sk_...`. It is the same code as this repo, deployed on Vercel; your key is forwarded to `vault.norc.app` and not stored.
|
|
52
|
+
|
|
49
53
|
## Tools
|
|
50
54
|
|
|
51
55
|
- `list_jobs`, `create_job`, `update_job`, `delete_job`
|
package/dist/handler.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
|
+
import { VaultClient } from './vault-client.js';
|
|
4
|
+
import { registerJobTools } from './tools/jobs.js';
|
|
5
|
+
import { registerGitopsTools } from './tools/gitops.js';
|
|
6
|
+
import { registerMachineTools } from './tools/machines.js';
|
|
7
|
+
import { registerRunTools } from './tools/runs.js';
|
|
8
|
+
const VAULT_BASE_URL = process.env.NORC_VAULT_URL ?? 'https://vault.norc.app';
|
|
9
|
+
export function extractApiKey(headers) {
|
|
10
|
+
const auth = headers.get('authorization') ?? '';
|
|
11
|
+
if (!auth.startsWith('Bearer '))
|
|
12
|
+
return null;
|
|
13
|
+
const raw = auth.slice('Bearer '.length).trim();
|
|
14
|
+
return raw.startsWith('norc_sk_') ? raw : null;
|
|
15
|
+
}
|
|
16
|
+
export function buildServer(apiKey) {
|
|
17
|
+
const server = new McpServer({ name: 'norc-mcp', version: '0.3.1' });
|
|
18
|
+
const client = new VaultClient(apiKey, VAULT_BASE_URL);
|
|
19
|
+
registerJobTools(server, client);
|
|
20
|
+
registerMachineTools(server, client);
|
|
21
|
+
registerRunTools(server, client);
|
|
22
|
+
registerGitopsTools(server, client);
|
|
23
|
+
return server;
|
|
24
|
+
}
|
|
25
|
+
// One stateless MCP exchange per request. Shared by the standalone listener (server.ts) and
|
|
26
|
+
// the Vercel function (api/mcp.js), which have different routing but identical behaviour.
|
|
27
|
+
export async function handleMcp(req, res) {
|
|
28
|
+
if (req.method !== 'POST') {
|
|
29
|
+
res.writeHead(405, { allow: 'POST' }).end();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const headers = new Headers(req.headers);
|
|
33
|
+
const apiKey = extractApiKey(headers);
|
|
34
|
+
if (!apiKey) {
|
|
35
|
+
res.writeHead(401, { 'content-type': 'application/json' }).end(JSON.stringify({ error: 'missing or malformed norc API key' }));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
// Vercel parses lazily on first access and throws on malformed JSON.
|
|
39
|
+
let body;
|
|
40
|
+
try {
|
|
41
|
+
body = req.body;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
res.writeHead(400, { 'content-type': 'application/json' }).end(JSON.stringify({ error: 'invalid JSON body' }));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const server = buildServer(apiKey);
|
|
48
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
49
|
+
res.on('close', () => {
|
|
50
|
+
transport.close();
|
|
51
|
+
server.close();
|
|
52
|
+
});
|
|
53
|
+
await server.connect(transport);
|
|
54
|
+
// Vercel pre-parses the body onto req.body; the standalone listener leaves the stream unread.
|
|
55
|
+
await transport.handleRequest(req, res, body);
|
|
56
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -2,31 +2,9 @@
|
|
|
2
2
|
import { realpathSync } from 'node:fs';
|
|
3
3
|
import { createServer } from 'node:http';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
5
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import { registerJobTools } from './tools/jobs.js';
|
|
10
|
-
import { registerGitopsTools } from './tools/gitops.js';
|
|
11
|
-
import { registerMachineTools } from './tools/machines.js';
|
|
12
|
-
import { registerRunTools } from './tools/runs.js';
|
|
13
|
-
const VAULT_BASE_URL = process.env.NORC_VAULT_URL ?? 'https://vault.norc.app';
|
|
14
|
-
export function extractApiKey(headers) {
|
|
15
|
-
const auth = headers.get('authorization') ?? '';
|
|
16
|
-
if (!auth.startsWith('Bearer '))
|
|
17
|
-
return null;
|
|
18
|
-
const raw = auth.slice('Bearer '.length).trim();
|
|
19
|
-
return raw.startsWith('norc_sk_') ? raw : null;
|
|
20
|
-
}
|
|
21
|
-
function buildServer(apiKey) {
|
|
22
|
-
const server = new McpServer({ name: 'norc-mcp', version: '0.3.0' });
|
|
23
|
-
const client = new VaultClient(apiKey, VAULT_BASE_URL);
|
|
24
|
-
registerJobTools(server, client);
|
|
25
|
-
registerMachineTools(server, client);
|
|
26
|
-
registerRunTools(server, client);
|
|
27
|
-
registerGitopsTools(server, client);
|
|
28
|
-
return server;
|
|
29
|
-
}
|
|
6
|
+
import { buildServer, extractApiKey, handleMcp } from './handler.js';
|
|
7
|
+
export { extractApiKey };
|
|
30
8
|
// stdio mode (a local MCP client spawns us, key comes from the environment) when
|
|
31
9
|
// NORC_API_KEY is set or --stdio is passed; otherwise the HTTP listener (Docker, self-hosting).
|
|
32
10
|
export function wantsStdio(env, argv) {
|
|
@@ -44,24 +22,11 @@ async function runStdio() {
|
|
|
44
22
|
function runHttp() {
|
|
45
23
|
const port = Number(process.env.PORT ?? 3000);
|
|
46
24
|
createServer(async (req, res) => {
|
|
47
|
-
if (req.url !== '/mcp'
|
|
25
|
+
if (req.url !== '/mcp') {
|
|
48
26
|
res.writeHead(404).end();
|
|
49
27
|
return;
|
|
50
28
|
}
|
|
51
|
-
|
|
52
|
-
const apiKey = extractApiKey(headers);
|
|
53
|
-
if (!apiKey) {
|
|
54
|
-
res.writeHead(401, { 'content-type': 'application/json' }).end(JSON.stringify({ error: 'missing or malformed norc API key' }));
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const server = buildServer(apiKey);
|
|
58
|
-
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
59
|
-
res.on('close', () => {
|
|
60
|
-
transport.close();
|
|
61
|
-
server.close();
|
|
62
|
-
});
|
|
63
|
-
await server.connect(transport);
|
|
64
|
-
await transport.handleRequest(req, res);
|
|
29
|
+
await handleMcp(req, res);
|
|
65
30
|
}).listen(port, () => {
|
|
66
31
|
console.log(`norc-mcp listening on :${port}`);
|
|
67
32
|
});
|