feat(mcp): реализовать серверную часть MCP, адаптеры, сервисы и скрипты приёмки
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
7380f18f15
commit
18c0a52171
1565 files changed
+175806
-5772
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import type { FastifyInstance, FastifyRequest } from "fastify"
|
||||
import { DatabaseRequestGate } from "../services/database-request-gate.js"
|
||||
import { sharedDatabaseGate } from "../services/shared-database-gate.js"
|
||||
import { withConfigurationActor } from "../services/config-mutation-policy.js"
|
||||
import { withDatabaseApiRequest } from "../modules/mcp/database-request-lease.js"
|
||||
const streams = new WeakMap<FastifyRequest, { cancelled: boolean; abort?: () => void }>()
|
||||
|
||||
export function registerDatabaseStreamAbort(request: FastifyRequest, abort: () => void): void {
|
||||
@@ -9,8 +11,8 @@ export function registerDatabaseStreamAbort(request: FastifyRequest, abort: () =
|
||||
if (state.cancelled) abort()
|
||||
}
|
||||
|
||||
export function installDatabaseRequestGate(app: FastifyInstance): void {
|
||||
const gate = new DatabaseRequestGate()
|
||||
export function installDatabaseRequestGate(app: FastifyInstance, admit = withDatabaseApiRequest): void {
|
||||
const gate = sharedDatabaseGate
|
||||
app.addHook("onRoute", options => {
|
||||
const path = options.url
|
||||
if (!path.startsWith("/api/") || path === "/api/auth/config") return
|
||||
@@ -18,9 +20,10 @@ export function installDatabaseRequestGate(app: FastifyInstance): void {
|
||||
const operation = path === "/api/system/database/backup" || path === "/api/system/database/restore"
|
||||
const stream = path === "/api/logs/live" || path === "/api/traffic/flow/live" || /^\/api\/traffic\/servers\/:id\/live$/.test(path)
|
||||
options.handler = async function (request, reply) {
|
||||
const run = async () => await original.call(this, request, reply)
|
||||
if (operation) return gate.exclusive(run)
|
||||
if (!stream) return gate.request(run)
|
||||
const run = async () => withConfigurationActor(request.authUser?.id ?? "system", async () => await original.call(this, request, reply))
|
||||
// The service owns exclusivity, including calls that do not originate in HTTP.
|
||||
if (operation) return run()
|
||||
if (!stream) return gate.request(() => admit(run))
|
||||
const state = { cancelled: false, abort: undefined as (() => void) | undefined }
|
||||
streams.set(request, state)
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user