Skip to content

Workers bindings mcp #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: fix type issues and PR feedback
  • Loading branch information
deloreyj committed Apr 15, 2025
commit 9d0c435002a9c04f85c07ccd7b805610ae30a7b3
3 changes: 1 addition & 2 deletions apps/workers-bindings/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "remote-mcp-server",
"name": "workers-bindings",
"version": "0.0.0",
"private": true,
"scripts": {
Expand All @@ -18,7 +18,6 @@
"marked": "15.0.7",
"typescript": "5.5.4",
"vitest": "3.0.9",
"workers-mcp": "^0.1.0-3",
"wrangler": "4.10.0"
},
"dependencies": {
Expand Down
4 changes: 3 additions & 1 deletion apps/workers-bindings/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OAuthProvider from '@cloudflare/workers-oauth-provider'
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { McpAgent } from 'agents/mcp'
import { env } from 'cloudflare:workers'

import {
CloudflareAuthHandler,
Expand Down Expand Up @@ -68,7 +69,8 @@ export default new OAuthProvider({
defaultHandler: CloudflareAuthHandler,
authorizeEndpoint: '/oauth/authorize',
tokenEndpoint: '/token',
tokenExchangeCallback: handleTokenExchangeCallback,
tokenExchangeCallback: (options) =>
handleTokenExchangeCallback(options, env.CLOUDFLARE_CLIENT_ID, env.CLOUDFLARE_CLIENT_SECRET),
// Cloudflare access token TTL
accessTokenTTL: 3600,
clientRegistrationEndpoint: '/register',
Expand Down
6 changes: 3 additions & 3 deletions apps/workers-bindings/worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Generated by Wrangler by running `wrangler types` (hash: bcea92b4b34ff43daede463c6e9dfc75)
// Generated by Wrangler by running `wrangler types` (hash: 83b65e4226fcf5092146edc626681982)
// Runtime types generated with [email protected] 2025-03-10 nodejs_compat
declare namespace Cloudflare {
interface Env {
OAUTH_KV: KVNamespace;
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
CLOUDFLARE_CLIENT_ID: string;
CLOUDFLARE_CLIENT_SECRET: string;
MCP_OBJECT: DurableObjectNamespace<import("./src/index").WorkersBindingsMCP>;
ASSETS: Fetcher;
}
}
interface Env extends Cloudflare.Env {}
Expand Down
8 changes: 3 additions & 5 deletions apps/workers-observability/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OAuthProvider from '@cloudflare/workers-oauth-provider'
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { McpAgent } from 'agents/mcp'
import { env } from 'cloudflare:workers'

import {
CloudflareAuthHandler,
Expand All @@ -12,7 +13,6 @@ import { registerWorkersTools } from '@repo/mcp-common/src/tools/worker'
import { registerLogsTools } from './tools/logs'

import type { AccountSchema, UserSchema } from '@repo/mcp-common/src/cloudflare-oauth-handler'
import type { Env } from '../worker-configuration'

// Context from the auth process, encrypted & stored in the auth token
// and provided to the DurableMCP as this.props
Expand All @@ -29,9 +29,6 @@ export class MyMCP extends McpAgent<Env, State, Props> {
name: 'Remote MCP Server with Workers Observability',
version: '1.0.0',
})
// TOOO: Why does this type need to be declared again on MyMCP?
// @ts-ignore
env!: Env

initialState: State = {
activeAccountId: null,
Expand Down Expand Up @@ -77,7 +74,8 @@ export default new OAuthProvider({
defaultHandler: CloudflareAuthHandler,
authorizeEndpoint: '/oauth/authorize',
tokenEndpoint: '/token',
tokenExchangeCallback: handleTokenExchangeCallback,
tokenExchangeCallback: (options) =>
handleTokenExchangeCallback(options, env.CLOUDFLARE_CLIENT_ID, env.CLOUDFLARE_CLIENT_SECRET),
// Cloudflare access token TTL
accessTokenTTL: 3600,
clientRegistrationEndpoint: '/register',
Expand Down
2 changes: 0 additions & 2 deletions apps/workers-observability/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'

import type { Env } from './worker-configuration'

export interface TestEnv extends Env {
CLOUDFLARE_MOCK_ACCOUNT_ID: string
CLOUDFLARE_MOCK_API_TOKEN: string
Expand Down
Loading
Loading