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
652652 const pid = typeof pidRecord?.pid === "number" ? pidRecord.pid : null;
653653
654654 if (pid === null) {
655− yield* Effect.tryPromise({
656− try: () => rm(DEFAULT_SERVER_PID_FILE, { force: true }),
657− catch: () => undefined,
658− });
655+ yield* Effect.tryPromise(() => rm(DEFAULT_SERVER_PID_FILE, { force: true })).pipe(
656+ Effect.ignore,
657+ );
659658 return false;
660659 }
661660
662661 if (!isPidRunning(pid)) {
663− yield* Effect.tryPromise({
664− try: () => rm(DEFAULT_SERVER_PID_FILE, { force: true }),
665− catch: () => undefined,
666− });
662+ yield* Effect.tryPromise(() => rm(DEFAULT_SERVER_PID_FILE, { force: true })).pipe(
663+ Effect.ignore,
664+ );
667665 return false;
668666 }
669667
@@ -674,10 +672,10 @@ const stopServer = (baseUrl: string) => · 4 unmodified lines
674672
675673 yield* waitForReachability(baseUrl, false).pipe(
676674 Effect.catchAll(() =>
677− Effect.tryPromise({
678− try: () => rm(DEFAULT_SERVER_PID_FILE, { force: true }),
679− catch: () => undefined,
680− }).pipe(Effect.zipRight(Effect.fail(new Error(`Timed out stopping local executor server pid ${pid}`)))),
675+ Effect.tryPromise(() => rm(DEFAULT_SERVER_PID_FILE, { force: true })).pipe(
676+ Effect.ignore,
677+ Effect.zipRight(Effect.fail(new Error(`Timed out stopping local executor server pid ${pid}`))),
678+ ),
681679 ),
682680 );
683681
apps/executor/src/distribution/harness.ts+2−1
@@ -176,7 +176,8 @@ export const LocalDistributionHarnessLive = Layer.scoped( · 175 unmodified lines
176176 }),
177177 (path) => Effect.tryPromise({
178178 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")),
180181 }).pipe(Effect.orDie),
181182 );
182183
apps/executor/src/server/server.test.ts+9−8
@@ -647,12 +647,13 @@ describe("local-executor-server", () => { · 646 unmodified lines
647647 });
648648
649649 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 }> }>,
651651 );
652652 expect(listed.tools.map((tool) => tool.name)).toEqual(["execute"]);
653− expect(mcp.client.getInstructions()).toContain(
654− `npx add-mcp \"${server.baseUrl}/mcp\" --transport http --name \"executor\"`,
655− );
653+ expect(listed.tools[0]?.description).toContain("Workflow:");
654+ expect(listed.tools[0]?.description).toContain("tools.discover");
655+ expect(listed.tools[0]?.description).toContain("tools.executor.sources.add");
656+
656657
657658 const executed = yield* Effect.promise(
658659 () =>
@@ -686,12 +687,12 @@ describe("local-executor-server", () => { · 27 unmodified lines
686687 });
687688
688689 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 }> }>,
690691 );
691692 expect(listed.tools.map((tool) => tool.name).sort()).toEqual(["execute", "resume"]);
692− expect(mcp.client.getInstructions()).toContain(
693− `npx add-mcp \"${server.baseUrl}/mcp\" --transport http --name \"executor\"`,
694− );
693+ expect(listed.tools.find((tool) => tool.name === "execute")?.description).toContain("Workflow:");
694+ expect(listed.tools.find((tool) => tool.name === "execute")?.description).toContain("tools.discover");
695+
695696
696697 const executed = yield* Effect.promise(
697698 () =>
apps/web/src/components/local-mcp-install-card.tsx+37−0
@@ -0,0 +1,37 @@
1+import { useEffect, useMemo, useState } from "react";
2+import { CodeBlock } from "./code-block";
3+
4+export 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
55 * control-plane handler. Everything else (frontend assets, HMR) is
66 * handled by Vite itself.
77 */
8+import * as Cause from "effect/Cause";
89 import * as Effect from "effect/Effect";
10+import * as Exit from "effect/Exit";
11+import * as Runtime from "effect/Runtime";
912 import * as Scope from "effect/Scope";
1013 import { createLocalExecutorRequestHandler } from "@executor-v3/server";
1114
@@ -16,28 +19,53 @@ const truncateForLog = (value: string): string => · 4 unmodified lines
1619 ? `${value.slice(0, MAX_LOGGED_ERROR_BODY_LENGTH)}... [truncated]`
1720 : value;
1821
19−const formatErrorForLog = (error: unknown) =>
20− error instanceof Error
21− ? {
22− name: error.name,
23− message: error.message,
24− stack: error.stack,
25− }
26− : error;
22+/**
23+ * Extract a detailed, human-readable description from an error.
24+ *
25+ * When Effect rejects via `runPromise`, the thrown value is a
26+ * `FiberFailure` wrapping a `Cause`. `Cause.pretty` renders the full
27+ * failure tree (defects, interrupts, tagged errors, etc.) rather than the
28+ * opaque fallback message ("An error has occurred").
29+ */
30+const 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+};
2742
2843 // Create a long-lived scope that stays open for the lifetime of the process.
29−const handlerPromise = Effect.runPromise(
30− Effect.gen(function* () {
31− const scope = yield* Scope.make();
32− const handler = yield* createLocalExecutorRequestHandler().pipe(
33− Effect.provideService(Scope.Scope, scope),
34− );
35− return handler;
36− }),
37−).catch((error) => {
38− console.error("[executor dev api] failed to initialize request handler", formatErrorForLog(error));
39− throw error;
40−});
44+const handlerPromise = (async () => {
45+ const exit = await Effect.runPromiseExit(
46+ Effect.gen(function* () {
47+ const scope = yield* Scope.make();
48+ const handler = yield* createLocalExecutorRequestHandler().pipe(
49+ Effect.provideService(Scope.Scope, scope),
50+ );
51+ return handler;
52+ }),
53+ );
54+
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+})();
4169
4270 export default {
4371 async fetch(request: Request) {
apps/web/src/views/add-source.tsx+9−0
@@ -18,6 +18,7 @@ import { · 17 unmodified lines
1818 } from "@executor-v3/react";
1919 import { Badge } from "../components/ui/badge";
2020 import { Button } from "../components/ui/button";
21+import { LocalMcpInstallCard } from "../components/local-mcp-install-card";
2122 import { SourceFavicon } from "../components/source-favicon";
2223 import {
2324 IconArrowLeft,
@@ -737,6 +738,14 @@ export function AddSourcePage() { · 713 unmodified lines
737738
738739 {statusBanner && <StatusBanner state={statusBanner} className="mb-6" />}
739740
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+ )}
740749 {/* Step 1: Discovery */}
741750 {(phase === "idle" || phase === "discovering") && (
742751 <div className="space-y-6">
apps/web/src/views/home.tsx+3−0
@@ -1,6 +1,7 @@
11 import { Link } from "@tanstack/react-router";
22 import { useSources, type Source } from "@executor-v3/react";
33 import { LoadableBlock } from "../components/loadable";
4+import { LocalMcpInstallCard } from "../components/local-mcp-install-card";
45 import { SourceFavicon } from "../components/source-favicon";
56 import { Badge } from "../components/ui/badge";
67 import { Button } from "../components/ui/button";
@@ -30,6 +31,8 @@ export function HomePage() { · 23 unmodified lines
3031 </Link>
3132 </div>
3233
34+ <LocalMcpInstallCard className="mb-8" />
35+
3336 {/* Source list */}
3437 <LoadableBlock loadable={sources} loading="Loading sources...">
3538 {(items) =>
apps/web/vite.config.ts+2−2
@@ -11,8 +11,8 @@ export default defineConfig({ · 10 unmodified lines
1111 devServer({
1212 entry: "src/dev.ts",
1313 exclude: [
14− // Only let /v1 requests reach the API handler
15− /^\/(?!v1(\/|$))/,
14+ // Only let /v1 and /mcp requests reach the API handler
15+ /^\/(?!(v1|mcp)(\/|$))/,
1616 /^\/(src|node_modules|@vite|@id|@react-refresh)/,
1717 /\.(css|ts|tsx|js|jsx|svg|png|jpg|gif|ico|woff2?|json|map)(\?.*)?$/,
1818 ],

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