Skip to content

Files

Latest commit

06d2347 · Jul 29, 2025

History

History
64 lines (45 loc) · 1.86 KB

File metadata and controls

64 lines (45 loc) · 1.86 KB

TypeScript SDK Example OAuth Client

This is a copy of the TypeScript SDK Example MCP OAuth Client with minor changes.

Minor Changes

The scope was updated to match that of the current deployment.

const clientMetadata: OAuthClientMetadata = {
    client_name: 'Simple OAuth MCP Client',
    redirect_uris: [CALLBACK_URL],
    grant_types: ['authorization_code'],
    response_types: ['code'],
    token_endpoint_auth_method: 'client_secret_post',
    scope: 'stocks/read'
};

The following code was added to support capturing MCP, OAuth and API requests in an HTTP proxy tool.

import { setGlobalDispatcher, ProxyAgent } from 'undici';

if (process.env.http_proxy) {
  const dispatcher = new ProxyAgent({uri: new URL(process.env.http_proxy).toString() });
  setGlobalDispatcher(dispatcher);
}

View MCP Messages with an HTTP Proxy

The following screenshot shows a streamable HTTP request when an MCP tool is called.

HTTP Proxy Capture

You first need to install an HTTP proxy tool like mitmproxy.
Save the following small script as init.py to limit traffic to the code example's URLs:

from mitmproxy import ctx

def load(loader):
    ctx.options.view_filter = "~d demo.example"

Run the proxy with a command like this, which will open the browser at http://localhost:8889.

mitmweb -p 8888 --web-port 8889 --script init.py

Then configure the HTTP proxy against the local computer's network connection:

HTTP Proxy Configure

You can run the MCP client with the following commands to route messages via the HTTP proxy tool.

cd mcp-client
export http_proxy='http://127.0.0.1:8888'
npm install
npm start