Skip to content

Commit 5cad782

Browse files
committed
Add the MCP auth scenario
1 parent 64d8984 commit 5cad782

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SAMPLE: Generate response from remote MCP through Responses API
2+
// PAGE: https://platform.openai.com/docs/guides/tools-connectors-mcp#authentication
3+
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
4+
#pragma warning disable OPENAI001
5+
6+
#:package OpenAI@2.*
7+
#:property PublishAot=false
8+
9+
using OpenAI.Responses;
10+
11+
string authToken = Environment.GetEnvironmentVariable("STRIPE_OAUTH_ACCESS_TOKEN")!;
12+
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
13+
OpenAIResponseClient client = new(model: "gpt-5", apiKey: key);
14+
15+
ResponseCreationOptions options = new();
16+
options.Tools.Add(ResponseTool.CreateMcpTool(
17+
serverLabel: "stripe",
18+
serverUri: new Uri("https://mcp.stripe.com"),
19+
authorizationToken: authToken
20+
));
21+
22+
OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
23+
ResponseItem.CreateUserMessageItem([
24+
ResponseContentPart.CreateInputTextPart("Create a payment link for $20")
25+
])
26+
], options);
27+
28+
Console.WriteLine(response.GetOutputText());

0 commit comments

Comments
 (0)