Add a Go example exercising hostedtool.MCPServer with the OpenAI Responses provider - #665
Open
PratikDhanave wants to merge 3 commits into
Open
Add a Go example exercising hostedtool.MCPServer with the OpenAI Responses provider#665PratikDhanave wants to merge 3 commits into
PratikDhanave wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new OpenAI Responses provider example demonstrating how to wire a hosted MCP server (hostedtool.MCPServer) into an agent, and registers that example with the cmd/verifyexamples harness.
Changes:
- Added
examples/02-agents/providers/openai/hosted_mcp/main.goto run an OpenAI Responses agent with the Microsoft Learn hosted MCP endpoint and print MCP tool-call / approval-request contents. - Registered the new example in
cmd/verifyexamples/examples.goso it can be verified (env-gated onOPENAI_API_KEY).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| examples/02-agents/providers/openai/hosted_mcp/main.go | New example showing a hosted MCP server tool used through an OpenAI Responses agent and printing MCP-related response contents. |
| cmd/verifyexamples/examples.go | Adds the new hosted MCP example to the verifyexamples registry with OPENAI_API_KEY gating. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+59
to
+63
| resp, err := a.RunText(context.Background(), "How do I create an Azure storage account using the az CLI?").Collect() | ||
| demo.Response(resp, err) | ||
| if resp == nil { | ||
| return | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Good catch — fixed in 1e6f593: the guard is now if err != nil || resp == nil { return }, so on error we stop before iterating resp.Contents() instead of printing partial tool-call records.
This comment has been minimized.
This comment has been minimized.
PratikDhanave
force-pushed
the
openai-hosted-mcp-example
branch
from
July 23, 2026 15:40
ae2fe1b to
2c9265d
Compare
This comment has been minimized.
This comment has been minimized.
PratikDhanave
force-pushed
the
openai-hosted-mcp-example
branch
from
July 24, 2026 01:40
2c9265d to
dcabd15
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Add examples/02-agents/providers/openai/hosted_mcp demonstrating the hostedtool.MCPServer tool with an OpenAI Responses agent. It attaches a remote hosted MCP server (Microsoft Learn), runs the agent, and inspects the response for MCPServerToolCallContent and MCP approval requests. The live run is guarded behind an OPENAI_API_KEY check. Register the example in the verifyexamples harness alongside the other hosted-tool examples.
PratikDhanave
force-pushed
the
openai-hosted-mcp-example
branch
from
July 24, 2026 09:34
1e6f593 to
9c54b9d
Compare
This comment has been minimized.
This comment has been minimized.
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new example
examples/02-agents/providers/openai/hosted_mcp/main.gothat wires a hosted MCP server into an OpenAI Responses agent.The example:
openaiprovider.NewResponsesAgent,[]tool.Tool{&hostedtool.MCPServer{...}}pointing at the public Microsoft Learn MCP endpoint (https://learn.microsoft.com/api/mcp) withAllowedToolsset,*message.MCPServerToolCallContentand hosted-MCP*message.ToolApprovalRequestContent,OPENAI_API_KEYcheck, printing a skip message when it is absent (consistent with the other provider examples).It is registered in the
cmd/verifyexamplesharness alongside the existing hosted-tool examples (foundrystep14_code_interpreter,step21_web_search,step23_local_mcp).Why
provider/openaiprovider/responses.goalready maps*hostedtool.MCPServerontoresponses.ToolMcpParam(server label, server URL/connector id, description, allowed tools, headers, authorization), but no example exercised it —hostedtool.MCPServerdid not appear anywhere underexamples/. The existing examples only wiredhostedtoolforCodeInterpreterandWebSearch. This mirrors the .NET and Python SDKs, which each ship a hosted-MCP agent sample, and fills the missing OpenAI Responses variant for cross-SDK parity. The example follows the same structure as the existing hosted-tool step examples.Testing
go build ./...go vet ./examples/... ./cmd/verifyexamples/...go test ./cmd/verifyexamples/...all pass. The example is a docs/example addition; its live body is env-gated so it compiles and vets without credentials.