This is a copy of the TypeScript SDK Example MCP OAuth Client with 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);
}
The following screenshot shows a streamable HTTP request when an MCP tool is called.
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:
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