GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(server): every T3 MCP tool declares who may call it · pingdotgg/t3code@2fb4872

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/mcp
    • McpDeviceToolkit.test.ts
    • McpHttpServer.test.ts
    • McpHttpServer.ts
    • McpToolAccess.test.ts
    • McpToolAccess.testkit.ts
    • McpToolAccess.ts
    • ThreadMetadataMcpService.test.ts
    • ThreadMetadataMcpService.ts
    • threadAccess.ts
    • toolkits
      • attachment
        • handlers.ts
      • core.test.ts
      • device
        • handlers.ts
        • tools.ts
      • environment
        • handlers.ts
      • html
        • handlers.ts
        • tools.ts
      • orchestrator
        • handlers.ts
        • tools.ts
      • previewControls
        • handlers.test.ts
        • handlers.ts
        • tools.ts
      • preview
        • handlers.ts
        • tools.ts
      • project
        • handlers.ts
      • pullRequests
        • handlers.test.ts
        • handlers.ts
        • tools.ts
      • thread
        • handlers.ts
      • worktree
        • handlers.ts
        • tools.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/mcp/McpDeviceToolkit.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpDeviceToolkit.test.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as ServerConfig from "../config.ts";
1414
import * as DeviceService from "../device/DeviceService.ts";
1515
import * as McpHttpServer from "./McpHttpServer.ts";
1616
import * as McpInvocationContext from "./McpInvocationContext.ts";
17+
import * as McpToolAccessTestkit from "./McpToolAccess.testkit.ts";
1718

1819
const environmentId = EnvironmentId.make("environment-device-test");
1920
const threadId = ThreadId.make("thread-device-test");
@@ -102,6 +103,7 @@ const layerDeviceServiceMock = Layer.mock(DeviceService.DeviceService)({
102103

103104
const layerTest = McpHttpServer.layerDeviceToolkit.pipe(
104105
Layer.provideMerge(McpServer.McpServer.layer),
106+
Layer.provideMerge(McpToolAccessTestkit.liveThreadsLayer),
105107
Layer.provideMerge(layerDeviceServiceMock),
106108
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-mcp-device-toolkit-test-" })),
107109
Layer.provide(NodeServices.layer),
@@ -172,6 +174,7 @@ it.effect("rejects unavailable agent access before booting or opening a device",
172174
Effect.provide(
173175
McpHttpServer.layerDeviceToolkit.pipe(
174176
Layer.provideMerge(McpServer.McpServer.layer),
177+
Layer.provideMerge(McpToolAccessTestkit.liveThreadsLayer),
175178
Layer.provide(layerUnavailable),
176179
Layer.provide(NodeServices.layer),
177180
),
Collapse file

‎apps/server/src/mcp/McpHttpServer.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpHttpServer.test.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { HttpBody, HttpClient, HttpRouter, HttpServerResponse } from "effect/htt
1717
import * as ProjectService from "../project/ProjectService.ts";
1818
import * as ServerConfig from "../config.ts";
1919
import * as McpHttpServer from "./McpHttpServer.ts";
20+
import * as McpToolAccessTestkit from "./McpToolAccess.testkit.ts";
2021
import * as McpInvocationContext from "./McpInvocationContext.ts";
2122
import * as PreviewAutomationBroker from "./PreviewAutomationBroker.ts";
2223

@@ -51,12 +52,14 @@ const client = McpSchema.McpServerClient.of({
5152
});
5253
const layerTest = McpHttpServer.layerPreviewToolkit.pipe(
5354
Layer.provideMerge(McpServer.McpServer.layer),
55+
Layer.provideMerge(McpToolAccessTestkit.liveThreadsLayer),
5456
Layer.provideMerge(PreviewAutomationBroker.layer),
5557
Layer.provideMerge(ServerConfig.layerTest(process.cwd(), { prefix: "t3-mcp-http-server-test-" })),
5658
Layer.provideMerge(NodeServices.layer),
5759
);
5860
const layerPullRequestsTest = McpHttpServer.layerPullRequestsToolkit.pipe(
5961
Layer.provideMerge(McpServer.McpServer.layer),
62+
Layer.provideMerge(McpToolAccessTestkit.liveThreadsLayer),
6063
Layer.provide(
6164
Layer.mergeAll(
6265
Layer.mock(ProjectService.ProjectService)({}),
Collapse file

‎apps/server/src/mcp/McpHttpServer.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpHttpServer.ts
+68-36Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as Schema from "effect/Schema";
1111
import * as Sink from "effect/Sink";
1212
import * as Stream from "effect/Stream";
1313
import type * as Types from "effect/Types";
14-
import { AiError, McpProtocol, McpSchema, McpServer, Tool } from "effect/ai";
14+
import { AiError, McpProtocol, McpSchema, McpServer, Tool, type Toolkit } from "effect/ai";
1515
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
1616
import { OrchestratorMcpFailure, PreviewAutomationError } from "@t3tools/contracts";
1717

@@ -20,7 +20,9 @@ import * as ServerConfig from "../config.ts";
2020
import * as DeviceService from "../device/DeviceService.ts";
2121
import * as HtmlRender from "../htmlRender/HtmlRender.ts";
2222
import * as PreviewBrowser from "../htmlRender/PreviewBrowser.ts";
23+
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
2324
import * as McpInvocationContext from "./McpInvocationContext.ts";
25+
import * as McpToolAccess from "./McpToolAccess.ts";
2426
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
2527
import { PreviewControlsToolkit } from "./toolkits/previewControls/tools.ts";
2628
import * as PreviewControlsHandlers from "./toolkits/previewControls/handlers.ts";
@@ -385,6 +387,7 @@ const previewSnapshotFailure = <E>(cause: Cause.Cause<E>) => {
385387
const registerPreviewSnapshot = Effect.fn("McpHttpServer.registerPreviewSnapshot")(function* () {
386388
const server = yield* McpServer.McpServer;
387389
const broker = yield* PreviewAutomationBroker.PreviewAutomationBroker;
390+
const threads = yield* ThreadManagementService.ThreadManagementService;
388391
// The MCP tool runner only supplies the client, so hand the save path its services here.
389392
const saveServices = yield* Effect.context<
390393
ServerConfig.ServerConfig | FileSystem.FileSystem | Path.Path
@@ -419,6 +422,7 @@ const registerPreviewSnapshot = Effect.fn("McpHttpServer.registerPreviewSnapshot
419422
Stream.run(Sink.last()),
420423
Effect.flatMap(Effect.fromOption),
421424
Effect.provideService(PreviewAutomationBroker.PreviewAutomationBroker, broker),
425+
Effect.provideService(ThreadManagementService.ThreadManagementService, threads),
422426
Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
423427
Effect.flatMap(({ encodedResult }) =>
424428
Effect.gen(function* () {
@@ -644,14 +648,19 @@ const registerImageTool = <T extends Tool.Any, E, R>(
644648

645649
const registerDeviceScreenshot = Effect.fn("McpHttpServer.registerDeviceScreenshot")(function* () {
646650
const devices = yield* DeviceService.DeviceService;
651+
const threads = yield* ThreadManagementService.ThreadManagementService;
647652
const built = yield* DeviceScreenshotToolkit;
648653
yield* registerImageTool(
649654
DeviceScreenshotTool,
650655
(payload) =>
651656
built
652657
.handle("device_screenshot", payload)
653658
.pipe(Stream.unwrap, Stream.run(Sink.last()), Effect.flatMap(Effect.fromOption)),
654-
(effect) => effect.pipe(Effect.provideService(DeviceService.DeviceService, devices)),
659+
(effect) =>
660+
effect.pipe(
661+
Effect.provideService(DeviceService.DeviceService, devices),
662+
Effect.provideService(ThreadManagementService.ThreadManagementService, threads),
663+
),
655664
"screenshot",
656665
"Device screenshot failed.",
657666
);
@@ -661,14 +670,19 @@ const isOrchestratorMcpFailure = Schema.is(OrchestratorMcpFailure);
661670

662671
const registerHtmlPreview = Effect.fn("McpHttpServer.registerHtmlPreview")(function* () {
663672
const htmlRender = yield* HtmlRender.HtmlRender;
673+
const threads = yield* ThreadManagementService.ThreadManagementService;
664674
const built = yield* HtmlPreviewToolkit;
665675
yield* registerImageTool(
666676
HtmlPreviewTool,
667677
(payload) =>
668678
built
669679
.handle("html_preview", payload)
670680
.pipe(Stream.unwrap, Stream.run(Sink.last()), Effect.flatMap(Effect.fromOption)),
671-
(effect) => effect.pipe(Effect.provideService(HtmlRender.HtmlRender, htmlRender)),
681+
(effect) =>
682+
effect.pipe(
683+
Effect.provideService(HtmlRender.HtmlRender, htmlRender),
684+
Effect.provideService(ThreadManagementService.ThreadManagementService, threads),
685+
),
672686
"preview",
673687
// Parameter errors and HTML render errors are both written by the server for the agent.
674688
(error) =>
@@ -678,65 +692,83 @@ const registerHtmlPreview = Effect.fn("McpHttpServer.registerHtmlPreview")(funct
678692
);
679693
});
680694

695+
/**
696+
* `McpServer.toolkit` for handlers that declared their access (see
697+
* `McpToolAccess`). Every toolkit on `/mcp` registers through this.
698+
*/
699+
const toolkitRegistration = <Tools extends Record<string, Tool.Any>, EX, RX>(
700+
toolkit: Toolkit.Toolkit<Tools>,
701+
handlers: McpToolAccess.HandlersLayer<Tools, EX, RX>,
702+
) => McpServer.toolkit(toolkit).pipe(Layer.provide(handlers));
703+
704+
/** A hand-registered tool, also only with handlers that declared their access. */
705+
const imageToolRegistration = <Tools extends Record<string, Tool.Any>, A, E, R, EX, RX>(
706+
register: Effect.Effect<A, E, R>,
707+
handlers: McpToolAccess.HandlersLayer<Tools, EX, RX>,
708+
) => Layer.effectDiscard(register).pipe(Layer.provide(handlers));
709+
681710
export const layerHtmlToolkit = Layer.mergeAll(
682-
McpServer.toolkit(HtmlRenderToolkit).pipe(Layer.provide(HtmlHandlers.layerRender)),
683-
Layer.effectDiscard(registerHtmlPreview()).pipe(Layer.provide(HtmlHandlers.layerPreview)),
711+
toolkitRegistration(HtmlRenderToolkit, HtmlHandlers.layerRender),
712+
imageToolRegistration(registerHtmlPreview(), HtmlHandlers.layerPreview),
684713
).pipe(Layer.provide(HtmlRender.layer), Layer.provide(PreviewBrowser.layer));
685714

686-
const layerPreviewStandardToolkitRegistration = McpServer.toolkit(PreviewStandardToolkit).pipe(
687-
Layer.provide(PreviewHandlers.layerStandard),
715+
const layerPreviewStandardToolkitRegistration = toolkitRegistration(
716+
PreviewStandardToolkit,
717+
PreviewHandlers.layerStandard,
688718
);
689719

690-
const layerPreviewSnapshotRegistration = Layer.effectDiscard(registerPreviewSnapshot()).pipe(
691-
Layer.provide(PreviewHandlers.layerSnapshot),
720+
const layerPreviewSnapshotRegistration = imageToolRegistration(
721+
registerPreviewSnapshot(),
722+
PreviewHandlers.layerSnapshot,
692723
);
693724

694725
export const layerPreviewToolkit = Layer.mergeAll(
695726
layerPreviewStandardToolkitRegistration,
696727
layerPreviewSnapshotRegistration,
697728
);
698729

699-
export const layerOrchestratorToolkit = McpServer.toolkit(OrchestratorToolkit).pipe(
700-
Layer.provide(OrchestratorHandlers.layer),
701-
Layer.provide(OrchestratorMcpService.layer),
702-
Layer.provide(ThreadMetadataMcpService.layer),
703-
);
730+
export const layerOrchestratorToolkit = toolkitRegistration(
731+
OrchestratorToolkit,
732+
OrchestratorHandlers.layer,
733+
).pipe(Layer.provide(OrchestratorMcpService.layer), Layer.provide(ThreadMetadataMcpService.layer));
704734

705-
export const layerThreadToolkit = McpServer.toolkit(ThreadToolkit).pipe(
706-
Layer.provide(ThreadHandlers.layer),
707-
);
735+
export const layerThreadToolkit = toolkitRegistration(ThreadToolkit, ThreadHandlers.layer);
708736

709-
const layerWorktreeToolkitRegistration = McpServer.toolkit(WorktreeToolkit).pipe(
710-
Layer.provide(WorktreeHandlers.layer),
711-
Layer.provide(WorktreeMcpService.layer),
712-
);
737+
const layerWorktreeToolkitRegistration = toolkitRegistration(
738+
WorktreeToolkit,
739+
WorktreeHandlers.layer,
740+
).pipe(Layer.provide(WorktreeMcpService.layer));
713741

714-
const layerPreviewControlsRegistration = McpServer.toolkit(PreviewControlsToolkit).pipe(
715-
Layer.provide(PreviewControlsHandlers.layer),
742+
const layerPreviewControlsRegistration = toolkitRegistration(
743+
PreviewControlsToolkit,
744+
PreviewControlsHandlers.layer,
716745
);
717746

718-
const layerEnvironmentRegistration = McpServer.toolkit(EnvironmentToolkit).pipe(
719-
Layer.provide(EnvironmentHandlers.layer),
747+
const layerEnvironmentRegistration = toolkitRegistration(
748+
EnvironmentToolkit,
749+
EnvironmentHandlers.layer,
720750
);
721751

722-
const layerProjectRegistration = McpServer.toolkit(ProjectToolkit).pipe(
723-
Layer.provide(ProjectHandlers.layer),
724-
);
752+
const layerProjectRegistration = toolkitRegistration(ProjectToolkit, ProjectHandlers.layer);
725753

726-
const layerAttachmentRegistration = McpServer.toolkit(AttachmentToolkit).pipe(
727-
Layer.provide(AttachmentHandlers.layer),
754+
const layerAttachmentRegistration = toolkitRegistration(
755+
AttachmentToolkit,
756+
AttachmentHandlers.layer,
728757
);
729758

730-
export const layerPullRequestsToolkit = McpServer.toolkit(PullRequestsToolkit).pipe(
731-
Layer.provide(PullRequestsHandlers.layer),
759+
export const layerPullRequestsToolkit = toolkitRegistration(
760+
PullRequestsToolkit,
761+
PullRequestsHandlers.layer,
732762
);
733763

734-
const layerDeviceStandardToolkitRegistration = McpServer.toolkit(DeviceStandardToolkit).pipe(
735-
Layer.provide(DeviceHandlers.layerStandard),
764+
const layerDeviceStandardToolkitRegistration = toolkitRegistration(
765+
DeviceStandardToolkit,
766+
DeviceHandlers.layerStandard,
736767
);
737768

738-
const layerDeviceScreenshotRegistration = Layer.effectDiscard(registerDeviceScreenshot()).pipe(
739-
Layer.provide(DeviceHandlers.layerScreenshot),
769+
const layerDeviceScreenshotRegistration = imageToolRegistration(
770+
registerDeviceScreenshot(),
771+
DeviceHandlers.layerScreenshot,
740772
);
741773

742774
export const layerDeviceToolkit = Layer.mergeAll(

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.