History

mcp server

Rhys Sullivan committed 8 months ago

Commit 8db6d7a1 parent 8cd05d616 files · +318 −96Browse files

Showing the changes to apps (8 of 16 files). Show all

Unified · Split

8 files
  1. apps/executor/src/cli/main.ts +10 −12
  2. apps/executor/src/distribution/harness.ts +2 −1
  3. apps/executor/src/server/server.test.ts +9 −8
  4. apps/web/src/components/local-mcp-install-card.tsx +37 −0
  5. apps/web/src/dev.ts +48 −20
  6. apps/web/src/views/add-source.tsx +9 −0
  7. apps/web/src/views/home.tsx +3 −0
  8. apps/web/vite.config.ts +2 −2
apps/executor/src/cli/main.ts+10−12
@@ -652,18 +652,16 @@ const stopServer = (baseUrl: string) => · 651 unmodified lines
652 const pid = typeof pidRecord?.pid === "number" ? pidRecord.pid : null;652 const pid = typeof pidRecord?.pid === "number" ? pidRecord.pid : null;
653 653
654 if (pid === null) {654 if (pid === null) {
655 yield* Effect.tryPromise({655 yield* Effect.tryPromise(() => rm(DEFAULT_SERVER_PID_FILE, { force: true })).pipe(
656 try: () => rm(DEFAULT_SERVER_PID_FILE, { force: true }),656 Effect.ignore,
657 catch: () => undefined,657 );
658 });
659 return false;658 return false;
660 }659 }
661 660
662 if (!isPidRunning(pid)) {661 if (!isPidRunning(pid)) {
663 yield* Effect.tryPromise({662 yield* Effect.tryPromise(() => rm(DEFAULT_SERVER_PID_FILE, { force: true })).pipe(
664 try: () => rm(DEFAULT_SERVER_PID_FILE, { force: true }),663 Effect.ignore,
665 catch: () => undefined,664 );
666 });
667 return false;665 return false;
668 }666 }
669 667
@@ -674,10 +672,10 @@ const stopServer = (baseUrl: string) => · 4 unmodified lines
674 672
675 yield* waitForReachability(baseUrl, false).pipe(673 yield* waitForReachability(baseUrl, false).pipe(
676 Effect.catchAll(() =>674 Effect.catchAll(() =>
677 Effect.tryPromise({675 Effect.tryPromise(() => rm(DEFAULT_SERVER_PID_FILE, { force: true })).pipe(
678 try: () => rm(DEFAULT_SERVER_PID_FILE, { force: true }),676 Effect.ignore,
679 catch: () => undefined,677 Effect.zipRight(Effect.fail(new Error(`Timed out stopping local executor server pid ${pid}`))),
680 }).pipe(Effect.zipRight(Effect.fail(new Error(`Timed out stopping local executor server pid ${pid}`)))),678 ),
681 ),679 ),
682 );680 );
683 681
apps/executor/src/distribution/harness.ts+2−1
@@ -176,7 +176,8 @@ export const LocalDistributionHarnessLive = Layer.scoped( · 175 unmodified lines
176 }),176 }),
177 (path) => Effect.tryPromise({177 (path) => Effect.tryPromise({
178 try: () => rm(path, { recursive: true, force: true }),178 try: () => rm(path, { recursive: true, force: true }),
179 catch: () => undefined,179 catch: (cause) =>
180 cause instanceof Error ? cause : new Error(String(cause ?? "temp dir cleanup failed")),
180 }).pipe(Effect.orDie),181 }).pipe(Effect.orDie),
181 );182 );
182 183
apps/executor/src/server/server.test.ts+9−8
@@ -647,12 +647,13 @@ describe("local-executor-server", () => { · 646 unmodified lines
647 });647 });
648 648
649 const listed = yield* Effect.promise(649 const listed = yield* Effect.promise(
650 () => mcp.client.listTools() as Promise<{ tools: Array<{ name: string }> }>,650 () => mcp.client.listTools() as Promise<{ tools: Array<{ name: string; description?: string }> }>,
651 );651 );
652 expect(listed.tools.map((tool) => tool.name)).toEqual(["execute"]);652 expect(listed.tools.map((tool) => tool.name)).toEqual(["execute"]);
653 expect(mcp.client.getInstructions()).toContain(653 expect(listed.tools[0]?.description).toContain("Workflow:");
654 `npx add-mcp \"${server.baseUrl}/mcp\" --transport http --name \"executor\"`,654 expect(listed.tools[0]?.description).toContain("tools.discover");
655 );655 expect(listed.tools[0]?.description).toContain("tools.executor.sources.add");
656
656 657
657 const executed = yield* Effect.promise(658 const executed = yield* Effect.promise(
658 () =>659 () =>
@@ -686,12 +687,12 @@ describe("local-executor-server", () => { · 27 unmodified lines
686 });687 });
687 688
688 const listed = yield* Effect.promise(689 const listed = yield* Effect.promise(
689 () => mcp.client.listTools() as Promise<{ tools: Array<{ name: string }> }>,690 () => mcp.client.listTools() as Promise<{ tools: Array<{ name: string; description?: string }> }>,
690 );691 );
691 expect(listed.tools.map((tool) => tool.name).sort()).toEqual(["execute", "resume"]);692 expect(listed.tools.map((tool) => tool.name).sort()).toEqual(["execute", "resume"]);
692 expect(mcp.client.getInstructions()).toContain(693 expect(listed.tools.find((tool) => tool.name === "execute")?.description).toContain("Workflow:");
693 `npx add-mcp \"${server.baseUrl}/mcp\" --transport http --name \"executor\"`,694 expect(listed.tools.find((tool) => tool.name === "execute")?.description).toContain("tools.discover");
694 );695
695 696
696 const executed = yield* Effect.promise(697 const executed = yield* Effect.promise(
697 () =>698 () =>
apps/web/src/components/local-mcp-install-card.tsx+37−0
@@ -0,0 +1,37 @@
1import { useEffect, useMemo, useState } from "react";
2import { CodeBlock } from "./code-block";
3
4export function LocalMcpInstallCard(props: {
5 title?: string;
6 description?: string;
7 className?: string;
8}) {
9 const [origin, setOrigin] = useState<string | null>(null);
10
11 useEffect(() => {
12 setOrigin(window.location.origin);
13 }, []);
14
15 const command = useMemo(
16 () =>
17 origin
18 ? `npx add-mcp "${origin}/mcp" --transport http --name "executor"`
19 : 'npx add-mcp "<this-server>/mcp" --transport http --name "executor"',
20 [origin],
21 );
22
23 return (
24 <section className={props.className ?? "rounded-2xl border border-border bg-card/80 p-5"}>
25 <div className="mb-3 space-y-1">
26 <h2 className="text-sm font-semibold text-foreground">
27 {props.title ?? "Install local MCP"}
28 </h2>
29 <p className="text-[13px] text-muted-foreground">
30 {props.description
31 ?? "Add this local executor server to an MCP client with one command. The URL uses the same origin as this web app."}
32 </p>
33 </div>
34 <CodeBlock code={command} lang="bash" className="rounded-xl border border-border bg-background/70" />
35 </section>
36 );
37}
apps/web/src/dev.ts+48−20
@@ -5,7 +5,10 @@ · 4 unmodified lines
5 * control-plane handler. Everything else (frontend assets, HMR) is5 * control-plane handler. Everything else (frontend assets, HMR) is
6 * handled by Vite itself.6 * handled by Vite itself.
7 */7 */
8import * as Cause from "effect/Cause";
8import * as Effect from "effect/Effect";9import * as Effect from "effect/Effect";
10import * as Exit from "effect/Exit";
11import * as Runtime from "effect/Runtime";
9import * as Scope from "effect/Scope";12import * as Scope from "effect/Scope";
10import { createLocalExecutorRequestHandler } from "@executor-v3/server";13import { createLocalExecutorRequestHandler } from "@executor-v3/server";
11 14
@@ -16,28 +19,53 @@ const truncateForLog = (value: string): string => · 4 unmodified lines
16 ? `${value.slice(0, MAX_LOGGED_ERROR_BODY_LENGTH)}... [truncated]`19 ? `${value.slice(0, MAX_LOGGED_ERROR_BODY_LENGTH)}... [truncated]`
17 : value;20 : value;
18 21
19const formatErrorForLog = (error: unknown) =>22/**
20 error instanceof Error23 * Extract a detailed, human-readable description from an error.
21 ? {24 *
22 name: error.name,25 * When Effect rejects via `runPromise`, the thrown value is a
23 message: error.message,26 * `FiberFailure` wrapping a `Cause`. `Cause.pretty` renders the full
24 stack: error.stack,27 * failure tree (defects, interrupts, tagged errors, etc.) rather than the
25 }28 * opaque fallback message ("An error has occurred").
26 : error;29 */
30const formatErrorForLog = (error: unknown): string => {
31 if (Runtime.isFiberFailure(error)) {
32 const cause = error[Runtime.FiberFailureCauseId];
33 return Cause.pretty(cause);
34 }
35
36 if (error instanceof Error) {
37 return error.stack ?? error.message;
38 }
39
40 return String(error);
41};
27 42
28// Create a long-lived scope that stays open for the lifetime of the process.43// Create a long-lived scope that stays open for the lifetime of the process.
29const handlerPromise = Effect.runPromise(44const handlerPromise = (async () => {
30 Effect.gen(function* () {45 const exit = await Effect.runPromiseExit(
31 const scope = yield* Scope.make();46 Effect.gen(function* () {
32 const handler = yield* createLocalExecutorRequestHandler().pipe(47 const scope = yield* Scope.make();
33 Effect.provideService(Scope.Scope, scope),48 const handler = yield* createLocalExecutorRequestHandler().pipe(
34 );49 Effect.provideService(Scope.Scope, scope),
35 return handler;50 );
36 }),51 return handler;
37).catch((error) => {52 }),
38 console.error("[executor dev api] failed to initialize request handler", formatErrorForLog(error));53 );
39 throw error;54
40});55 if (Exit.isSuccess(exit)) {
56 return exit.value;
57 }
58
59 // Log the full Cause tree — this captures typed errors, defects (uncaught
60 // throws), and interrupts with their original stack traces.
61 console.error(
62 "[executor dev api] failed to initialize request handler\n\n" +
63 Cause.pretty(exit.cause),
64 );
65
66 // Re-throw so every subsequent request sees the init failure.
67 throw Cause.squash(exit.cause);
68})();
41 69
42export default {70export default {
43 async fetch(request: Request) {71 async fetch(request: Request) {
apps/web/src/views/add-source.tsx+9−0
@@ -18,6 +18,7 @@ import { · 17 unmodified lines
18} from "@executor-v3/react";18} from "@executor-v3/react";
19import { Badge } from "../components/ui/badge";19import { Badge } from "../components/ui/badge";
20import { Button } from "../components/ui/button";20import { Button } from "../components/ui/button";
21import { LocalMcpInstallCard } from "../components/local-mcp-install-card";
21import { SourceFavicon } from "../components/source-favicon";22import { SourceFavicon } from "../components/source-favicon";
22import {23import {
23 IconArrowLeft,24 IconArrowLeft,
@@ -737,6 +738,14 @@ export function AddSourcePage() { · 713 unmodified lines
737 738
738 {statusBanner && <StatusBanner state={statusBanner} className="mb-6" />}739 {statusBanner && <StatusBanner state={statusBanner} className="mb-6" />}
739 740
741
742 {(phase === "idle" || phase === "discovering") && (
743 <LocalMcpInstallCard
744 className="mb-6 rounded-xl border border-border bg-card/80 p-5"
745 title="Install this executor as MCP"
746 description="Prefer a one-command setup? Install this local executor server into your MCP client, or add an external MCP source below."
747 />
748 )}
740 {/* Step 1: Discovery */}749 {/* Step 1: Discovery */}
741 {(phase === "idle" || phase === "discovering") && (750 {(phase === "idle" || phase === "discovering") && (
742 <div className="space-y-6">751 <div className="space-y-6">
apps/web/src/views/home.tsx+3−0
@@ -1,6 +1,7 @@
1import { Link } from "@tanstack/react-router";1import { Link } from "@tanstack/react-router";
2import { useSources, type Source } from "@executor-v3/react";2import { useSources, type Source } from "@executor-v3/react";
3import { LoadableBlock } from "../components/loadable";3import { LoadableBlock } from "../components/loadable";
4import { LocalMcpInstallCard } from "../components/local-mcp-install-card";
4import { SourceFavicon } from "../components/source-favicon";5import { SourceFavicon } from "../components/source-favicon";
5import { Badge } from "../components/ui/badge";6import { Badge } from "../components/ui/badge";
6import { Button } from "../components/ui/button";7import { Button } from "../components/ui/button";
@@ -30,6 +31,8 @@ export function HomePage() { · 23 unmodified lines
30 </Link>31 </Link>
31 </div>32 </div>
32 33
34 <LocalMcpInstallCard className="mb-8" />
35
33 {/* Source list */}36 {/* Source list */}
34 <LoadableBlock loadable={sources} loading="Loading sources...">37 <LoadableBlock loadable={sources} loading="Loading sources...">
35 {(items) =>38 {(items) =>
apps/web/vite.config.ts+2−2
@@ -11,8 +11,8 @@ export default defineConfig({ · 10 unmodified lines
11 devServer({11 devServer({
12 entry: "src/dev.ts",12 entry: "src/dev.ts",
13 exclude: [13 exclude: [
14 // Only let /v1 requests reach the API handler14 // Only let /v1 and /mcp requests reach the API handler
15 /^\/(?!v1(\/|$))/,15 /^\/(?!(v1|mcp)(\/|$))/,
16 /^\/(src|node_modules|@vite|@id|@react-refresh)/,16 /^\/(src|node_modules|@vite|@id|@react-refresh)/,
17 /\.(css|ts|tsx|js|jsx|svg|png|jpg|gif|ico|woff2?|json|map)(\?.*)?$/,17 /\.(css|ts|tsx|js|jsx|svg|png|jpg|gif|ico|woff2?|json|map)(\?.*)?$/,
18 ],18 ],

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t