| 1 | import * as McpProtocol from "effect/ai/McpProtocol" |
| 2 | import * as McpServer from "effect/ai/McpServer" |
| 3 | import { constVoid } from "effect/Function" |
| 4 | import * as Layer from "effect/Layer" |
| 5 | import * as Logger from "effect/Logger" |
| 6 | import * as References from "effect/References" |
| 7 | import type * as Schema from "effect/Schema" |
| 8 | |
| 9 | const noopLogger = Logger.make(constVoid) |
| 10 | |
| 11 | export const makeServerLayer = (options: { |
| 12 | readonly name: string |
| 13 | readonly version?: string | undefined |
| 14 | readonly instructions?: string | undefined |
| 15 | readonly protocols?: |
| 16 | | readonly [ |
| 17 | McpProtocol.ProtocolAdapter, |
| 18 | ...Array<McpProtocol.ProtocolAdapter> |
| 19 | ] |
| 20 | | undefined |
| 21 | readonly extensions?: Readonly<Record<`${string}/${string}`, Schema.Json>> | undefined |
| 22 | readonly allowedOrigins?: ReadonlyArray<string> | undefined |
| 23 | }) => |
| 24 | McpServer.layerHttp({ |
| 25 | name: options.name, |
| 26 | version: options.version ?? "1.0.0", |
| 27 | instructions: options.instructions, |
| 28 | path: "/mcp", |
| 29 | protocols: options.protocols ?? [McpProtocol.v2025_06_18], |
| 30 | allowedOrigins: ["https://allowed.example"], |
| 31 | extensions: options.extensions |
| 32 | }).pipe( |
| 33 | Layer.provideMerge(Layer.succeed( |
| 34 | References.CurrentLoggers, |
| 35 | new Set([noopLogger]) |
| 36 | )) |
| 37 | ) |