Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ allowlist, without ever exposing the upstream token or key.
```
brokers/discord Discord broker Worker
brokers/github GitHub broker Worker
packages/ shared packages (none yet)
packages/core broker-core: code both brokers share
```

One npm workspace; `npm install` at the root installs everything.

## What is shared

`packages/core` (`broker-core`) holds what both brokers use: the utilities (`publicUrl`, `required`, `base64url`) and `VERSION`; the tool types with `ToolInputError`, `validateArgs` and `truncate`; the MCP server; the sign-in flow and its pages; `createBroker`, the request router; the two `Feed` helpers; and, under `broker-core/testing`, the in-memory KV and sign-in driver the tests use. `vitest.shared.ts` holds the test settings every package shares, including the Node stand-in for `cloudflare:workers`. Every `package.json` states the same version, and a core test checks that.

## Commands

```sh
npm install
npm run typecheck # both brokers
npm test # both brokers
npm run typecheck # core and both brokers
npm test # core and both brokers
```

## Deploying
Expand Down
9 changes: 5 additions & 4 deletions brokers/discord/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ token or the OAuth client secret. Callers send ordinary `Request`s such as

`DISCORD_ALLOWED_GUILDS` and `DISCORD_ALLOWED_CHANNELS` apply to `/api/...` exactly as they
do to `discord_request`. `POST /signin` does not check `ALLOWED_DISCORD_USERS`; the caller
decides who may sign in. Each call logs one `feed` line (path, status, ms; never bodies).
decides who may sign in. Each call logs one `feed` line (event, method, path, status, ms; never bodies).

A consumer binds it in its own `wrangler.jsonc`:

Expand Down Expand Up @@ -269,7 +269,7 @@ post under that agent's name.
## Development

```sh
npm test # vitest: client (rate limits, breakers), tools, scope, MCP conformance, full OAuth flow
npm test # vitest: client (rate limits, breakers), tools, scope, Feed, full OAuth flow (MCP protocol conformance is tested in packages/core)
npm run typecheck
cp .dev.vars.example .dev.vars && npm run dev # local workerd on :8787
```
Expand All @@ -279,8 +279,9 @@ The tests run the server against the official MCP clients (`@modelcontextprotoco
sign-in: registration → consent → Discord (faked) → token → MCP calls. Discord's API is
faked at the fetch layer; no test touches a real token.

Layout: `src/index.ts` (routing, OAuth roles), `src/auth.ts` (consent, Discord sign-in,
allowlist, config checks), `src/mcp.ts` (transport, identical to github-broker's),
Layout: `src/index.ts` (wires `createBroker` from `broker-core`), `src/signin.ts` (Discord
sign-in, allowlist, config checks). The MCP server, consent pages and sign-in flow come from
`broker-core`. Also:
`src/feed.ts` (the internal `Feed` entrypoint), `src/shared.ts` (isolate-wide limiter and cache),
`src/tools.ts`, `src/discord/client.ts` (REST client, rate limits),
`src/discord/scope.ts` (guild/channel allowlists).
Expand Down
4 changes: 2 additions & 2 deletions brokers/discord/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-broker",
"version": "0.2.0",
"version": "0.3.0",
"private": true,
"license": "MIT",
"description": "Remote MCP server on Cloudflare Workers that brokers a Discord bot without exposing its token",
Expand All @@ -13,6 +13,6 @@
"cf-typegen": "wrangler types"
},
"dependencies": {
"@cloudflare/workers-oauth-provider": "1.2.4"
"broker-core": "*"
}
}
290 changes: 0 additions & 290 deletions brokers/discord/src/auth.ts

This file was deleted.

4 changes: 3 additions & 1 deletion brokers/discord/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface Env {
import type { BaseEnv } from "broker-core";

export interface Env extends BaseEnv {
/** KV namespace the OAuth library keeps clients, grants and tokens in. */
OAUTH_KV: KVNamespace;

Expand Down
Loading
Loading