test(ast-grep-mcp): batch 12 (3 files)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createInterface } from "node:readline";
|
||||
import type { Readable, Writable } from "node:stream";
|
||||
import { CLI_LANGUAGES } from "./constants";
|
||||
import { runJsonRpcStdioServer, type McpStdioServerOptions } from "./mcp-stdio-server";
|
||||
import { getPatternHint } from "./pattern-hints";
|
||||
import { formatReplaceResult, formatSearchResult } from "./result-formatter";
|
||||
import { runSg, type RunOptions } from "./runner";
|
||||
@@ -116,23 +117,12 @@ export async function handleAstGrepMcpRequest(input: unknown, options: AstGrepMc
|
||||
}
|
||||
|
||||
export async function runMcpStdioServer(
|
||||
input: NodeJS.ReadableStream = process.stdin,
|
||||
output: NodeJS.WritableStream = process.stdout,
|
||||
input: Readable = process.stdin,
|
||||
output: Writable = process.stdout,
|
||||
options: AstGrepMcpOptions = {},
|
||||
stdioOptions: McpStdioServerOptions = {},
|
||||
): Promise<void> {
|
||||
const lines = createInterface({ input, crlfDelay: Number.POSITIVE_INFINITY });
|
||||
for await (const line of lines) {
|
||||
if (!line.trim()) continue;
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(line);
|
||||
} catch (error) {
|
||||
output.write(`${JSON.stringify(errorResponse(null, -32700, "Parse error", messageFromError(error)))}\n`);
|
||||
continue;
|
||||
}
|
||||
const response = await handleAstGrepMcpRequest(parsed, options);
|
||||
if (response) output.write(`${JSON.stringify(response)}\n`);
|
||||
}
|
||||
await runJsonRpcStdioServer(handleAstGrepMcpRequest, input, output, options, stdioOptions);
|
||||
}
|
||||
|
||||
async function handleToolCall(id: JsonRpcId, params: unknown, options: AstGrepMcpOptions): Promise<JsonRpcResponse> {
|
||||
|
||||
Reference in New Issue
Block a user