feat(mcp): add compatible protocol workflows and execution services

This commit is contained in:
DrSmoothl committed 2026-10-23 21:19:37 +08:00
1 parent 9e7da154ff
commit 8e28bca775
31 files changed
+7317 -56

No files matched your search

@@ -1,4 +1,4 @@
import { createLogger } from '@snowluma/common/logger';
import { createLogger, runWithTraceRequest } from '@snowluma/common/logger';
import { WebSocketServer } from '@snowluma/websocket';
import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'http';
import type { ApiHandler } from '../api-handler';
@@ -13,6 +13,7 @@ import {
import { IOneBotNetworkAdapter, type AdapterStatus, type NetworkAdapterContext } from './adapter';
import { isAuthorized, normalizePath } from './utils';
import { WsServerConnections } from './ws-server-connections';
import { httpTraceparent } from './http-trace';
const moduleLog = createLogger('OneBot.HTTP');
@@ -345,7 +346,11 @@ export class HttpServerAdapter extends IOneBotNetworkAdapter<HttpServerNetwork>
});
}
private async handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void> {
private handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void> {
return runWithTraceRequest(() => this.handleRequestInContext(req, res));
}
private async handleRequestInContext(req: IncomingMessage, res: ServerResponse): Promise<void> {
const apiQuiescedAtIngress = this.ctx.api.isAcceptingActions === false;
if (apiQuiescedAtIngress) {
@@ -382,6 +387,16 @@ export class HttpServerAdapter extends IOneBotNetworkAdapter<HttpServerNetwork>
return;
}
if (req.headers.traceparent !== undefined) {
const traceparent = httpTraceparent(req.headers.traceparent);
if (traceparent) {
this.log.trace('http_trace traceparent=%s', traceparent);
} else {
this.log.trace('http_trace ignored invalid traceparent');
}
}
if (req.method === 'GET' && !action) {
respond(200, { status: 'ok', retcode: 0, data: { online: true } });
return;
+21
View File
@@ -0,0 +1,21 @@
/** Accept W3C traceparent without treating caller-supplied IDs as local request IDs. */
export function httpTraceparent(value: unknown): string | undefined {
if (typeof value !== 'string' || /[^\x21-\x7e]/.test(value)) {
return undefined;
}
const match = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(.*)$/.exec(value);
if (
!match ||
match[1] === 'ff' ||
/^0+$/.test(match[2]!) ||
/^0+$/.test(match[3]!) ||
(match[1] === '00' ? match[5] !== '' : match[5] !== '' && !match[5]!.startsWith('-'))
) {
return undefined;
}
// Future-version fields are opaque and must not enter application logs.
return value.slice(0, 55);
}