@hasna/brains 0.0.24 → 0.0.25
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/mcp/http.d.ts +14 -13
- package/dist/mcp/http.d.ts.map +1 -1
- package/dist/mcp/index.js +48 -88
- package/package.json +1 -1
package/dist/mcp/http.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare
|
|
5
|
-
export declare function
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export declare const DEFAULT_MCP_HTTP_PORT = 8802;
|
|
3
|
+
export declare const MCP_HTTP_HOST = "127.0.0.1";
|
|
4
|
+
export declare const MCP_SERVICE_NAME = "brains";
|
|
5
|
+
export declare function isHttpMode(args: string[]): boolean;
|
|
6
|
+
export declare function resolveMcpHttpPort(args: string[]): number;
|
|
7
|
+
export declare function healthPayload(name?: string): {
|
|
8
|
+
status: string;
|
|
9
|
+
name: string;
|
|
10
10
|
};
|
|
11
|
-
export declare function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export declare function handleMcpRequest(req: Request, buildServer: () => Server): Promise<Response>;
|
|
12
|
+
export declare function startMcpHttpServer(options: {
|
|
13
|
+
name: string;
|
|
14
|
+
port: number;
|
|
15
|
+
buildServer: () => Server;
|
|
16
|
+
}): ReturnType<typeof Bun.serve>;
|
|
16
17
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/mcp/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/mcp/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/mcp/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAExE,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,aAAa,cAAc,CAAC;AACzC,eAAO,MAAM,gBAAgB,WAAW,CAAC;AAEzC,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAElD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAQzD;AAED,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAyB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAE/F;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,MAAM,MAAM,GACxB,OAAO,CAAC,QAAQ,CAAC,CAOnB;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,MAAM,CAAC;CAC3B,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAoB/B"}
|
package/dist/mcp/index.js
CHANGED
|
@@ -24120,97 +24120,52 @@ var McpFinetuneStatusSchema = exports_external2.object({
|
|
|
24120
24120
|
});
|
|
24121
24121
|
|
|
24122
24122
|
// src/mcp/http.ts
|
|
24123
|
-
import {
|
|
24124
|
-
|
|
24125
|
-
var
|
|
24126
|
-
var
|
|
24127
|
-
function isHttpMode(
|
|
24128
|
-
return
|
|
24129
|
-
}
|
|
24130
|
-
function resolveMcpHttpPort(
|
|
24131
|
-
const portIdx =
|
|
24132
|
-
if (portIdx
|
|
24133
|
-
return
|
|
24134
|
-
}
|
|
24135
|
-
|
|
24136
|
-
|
|
24137
|
-
|
|
24123
|
+
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
24124
|
+
var DEFAULT_MCP_HTTP_PORT = 8802;
|
|
24125
|
+
var MCP_HTTP_HOST = "127.0.0.1";
|
|
24126
|
+
var MCP_SERVICE_NAME = "brains";
|
|
24127
|
+
function isHttpMode(args) {
|
|
24128
|
+
return args.includes("--http") || process.env.MCP_HTTP === "1";
|
|
24129
|
+
}
|
|
24130
|
+
function resolveMcpHttpPort(args) {
|
|
24131
|
+
const portIdx = args.indexOf("--port");
|
|
24132
|
+
if (portIdx >= 0 && args[portIdx + 1]) {
|
|
24133
|
+
return Number(args[portIdx + 1]);
|
|
24134
|
+
}
|
|
24135
|
+
const envPort = process.env.MCP_HTTP_PORT;
|
|
24136
|
+
if (envPort)
|
|
24137
|
+
return Number(envPort);
|
|
24138
24138
|
return DEFAULT_MCP_HTTP_PORT;
|
|
24139
24139
|
}
|
|
24140
|
-
function
|
|
24141
|
-
|
|
24142
|
-
if (!Number.isInteger(parsed) || parsed < 0 || parsed > 65535) {
|
|
24143
|
-
throw new Error(`Invalid ${source} value "${raw}". Expected 0-65535.`);
|
|
24144
|
-
}
|
|
24145
|
-
return parsed;
|
|
24140
|
+
function healthPayload(name = MCP_SERVICE_NAME) {
|
|
24141
|
+
return { status: "ok", name };
|
|
24146
24142
|
}
|
|
24147
|
-
async function
|
|
24148
|
-
const
|
|
24149
|
-
|
|
24150
|
-
|
|
24151
|
-
|
|
24152
|
-
|
|
24153
|
-
|
|
24154
|
-
return;
|
|
24155
|
-
return JSON.parse(text2);
|
|
24143
|
+
async function handleMcpRequest(req, buildServer) {
|
|
24144
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
24145
|
+
sessionIdGenerator: undefined
|
|
24146
|
+
});
|
|
24147
|
+
const server = buildServer();
|
|
24148
|
+
await server.connect(transport);
|
|
24149
|
+
return transport.handleRequest(req);
|
|
24156
24150
|
}
|
|
24157
|
-
|
|
24158
|
-
const
|
|
24159
|
-
const
|
|
24160
|
-
|
|
24161
|
-
|
|
24162
|
-
|
|
24163
|
-
const url = new URL(req.url
|
|
24164
|
-
if (
|
|
24165
|
-
|
|
24166
|
-
res.end(JSON.stringify({ status: "ok", name: serviceName }));
|
|
24167
|
-
return;
|
|
24168
|
-
}
|
|
24169
|
-
if (url.pathname !== "/mcp") {
|
|
24170
|
-
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
24171
|
-
res.end("Not Found");
|
|
24172
|
-
return;
|
|
24151
|
+
function startMcpHttpServer(options) {
|
|
24152
|
+
const { name, port, buildServer } = options;
|
|
24153
|
+
const server = Bun.serve({
|
|
24154
|
+
hostname: MCP_HTTP_HOST,
|
|
24155
|
+
port,
|
|
24156
|
+
async fetch(req) {
|
|
24157
|
+
const url = new URL(req.url);
|
|
24158
|
+
if (url.pathname === "/health" && req.method === "GET") {
|
|
24159
|
+
return Response.json(healthPayload(name));
|
|
24173
24160
|
}
|
|
24174
|
-
|
|
24175
|
-
|
|
24176
|
-
sessionIdGenerator: undefined
|
|
24177
|
-
});
|
|
24178
|
-
await server.connect(transport);
|
|
24179
|
-
let parsedBody;
|
|
24180
|
-
if (req.method === "POST") {
|
|
24181
|
-
parsedBody = await readJsonBody(req);
|
|
24182
|
-
}
|
|
24183
|
-
await transport.handleRequest(req, res, parsedBody);
|
|
24184
|
-
res.on("close", () => {
|
|
24185
|
-
transport.close();
|
|
24186
|
-
server.close();
|
|
24187
|
-
});
|
|
24188
|
-
} catch (error) {
|
|
24189
|
-
console.error(`[${serviceName}-mcp] HTTP error:`, error);
|
|
24190
|
-
if (!res.headersSent) {
|
|
24191
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
24192
|
-
res.end(JSON.stringify({
|
|
24193
|
-
jsonrpc: "2.0",
|
|
24194
|
-
error: { code: -32603, message: "Internal server error" },
|
|
24195
|
-
id: null
|
|
24196
|
-
}));
|
|
24161
|
+
if (url.pathname === "/mcp") {
|
|
24162
|
+
return handleMcpRequest(req, buildServer);
|
|
24197
24163
|
}
|
|
24164
|
+
return new Response("Not Found", { status: 404 });
|
|
24198
24165
|
}
|
|
24199
24166
|
});
|
|
24200
|
-
|
|
24201
|
-
|
|
24202
|
-
httpServer.listen(requestedPort, host, () => resolve3());
|
|
24203
|
-
});
|
|
24204
|
-
const addr = httpServer.address();
|
|
24205
|
-
const port = typeof addr === "object" && addr ? addr.port : requestedPort;
|
|
24206
|
-
console.error(`[${serviceName}-mcp] Streamable HTTP listening on http://${host}:${port}/mcp`);
|
|
24207
|
-
return {
|
|
24208
|
-
port,
|
|
24209
|
-
host,
|
|
24210
|
-
close: () => new Promise((resolve3, reject) => {
|
|
24211
|
-
httpServer.close((err) => err ? reject(err) : resolve3());
|
|
24212
|
-
})
|
|
24213
|
-
};
|
|
24167
|
+
console.error(`${name}-mcp HTTP listening on http://${MCP_HTTP_HOST}:${port}/mcp`);
|
|
24168
|
+
return server;
|
|
24214
24169
|
}
|
|
24215
24170
|
|
|
24216
24171
|
// src/mcp/index.ts
|
|
@@ -24703,15 +24658,20 @@ async function main() {
|
|
|
24703
24658
|
`);
|
|
24704
24659
|
return;
|
|
24705
24660
|
}
|
|
24706
|
-
|
|
24707
|
-
|
|
24708
|
-
|
|
24661
|
+
const args = process.argv.slice(2);
|
|
24662
|
+
if (isHttpMode(args)) {
|
|
24663
|
+
const handle = startMcpHttpServer({
|
|
24664
|
+
name: "brains",
|
|
24665
|
+
port: resolveMcpHttpPort(args),
|
|
24666
|
+
buildServer
|
|
24709
24667
|
});
|
|
24710
24668
|
process.on("SIGINT", () => {
|
|
24711
|
-
handle.
|
|
24669
|
+
handle.stop();
|
|
24670
|
+
process.exit(0);
|
|
24712
24671
|
});
|
|
24713
24672
|
process.on("SIGTERM", () => {
|
|
24714
|
-
handle.
|
|
24673
|
+
handle.stop();
|
|
24674
|
+
process.exit(0);
|
|
24715
24675
|
});
|
|
24716
24676
|
return;
|
|
24717
24677
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/brains",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "Fine-tuned model tracker and trainer — wraps OpenAI + Thinker Labs, gathers training data from todos/mementos/conversations/sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|