Skip to content

Add a Go example exercising hostedtool.MCPServer with the OpenAI Responses provider - #665

Open
PratikDhanave wants to merge 3 commits into
microsoft:mainfrom
PratikDhanaveFork:openai-hosted-mcp-example
Open

Add a Go example exercising hostedtool.MCPServer with the OpenAI Responses provider#665
PratikDhanave wants to merge 3 commits into
microsoft:mainfrom
PratikDhanaveFork:openai-hosted-mcp-example

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

Adds a new example examples/02-agents/providers/openai/hosted_mcp/main.go that wires a hosted MCP server into an OpenAI Responses agent.

The example:

  • builds an OpenAI Responses agent via openaiprovider.NewResponsesAgent,
  • attaches []tool.Tool{&hostedtool.MCPServer{...}} pointing at the public Microsoft Learn MCP endpoint (https://learn.microsoft.com/api/mcp) with AllowedTools set,
  • runs the agent and iterates the response contents, printing any *message.MCPServerToolCallContent and hosted-MCP *message.ToolApprovalRequestContent,
  • guards the live run behind an OPENAI_API_KEY check, printing a skip message when it is absent (consistent with the other provider examples).

It is registered in the cmd/verifyexamples harness alongside the existing hosted-tool examples (foundry step14_code_interpreter, step21_web_search, step23_local_mcp).

Why

provider/openaiprovider/responses.go already maps *hostedtool.MCPServer onto responses.ToolMcpParam (server label, server URL/connector id, description, allowed tools, headers, authorization), but no example exercised it — hostedtool.MCPServer did not appear anywhere under examples/. The existing examples only wired hostedtool for CodeInterpreter and WebSearch. 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.

Copilot AI review requested due to automatic review settings July 23, 2026 08:21
@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 23, 2026 08:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go to 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.go so it can be verified (env-gated on OPENAI_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
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 23, 2026
@PratikDhanave
PratikDhanave force-pushed the openai-hosted-mcp-example branch from ae2fe1b to 2c9265d Compare July 23, 2026 15:40
@github-actions

This comment has been minimized.

@PratikDhanave
PratikDhanave force-pushed the openai-hosted-mcp-example branch from 2c9265d to dcabd15 Compare July 24, 2026 01:40
@github-actions

This comment has been minimized.

@github-actions

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
PratikDhanave force-pushed the openai-hosted-mcp-example branch from 1e6f593 to 9c54b9d Compare July 24, 2026 09:34
@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Generated by Go API Consistency Review Agent · sonnet46 · 15.7 AIC · ⌖ 4.61 AIC · ⊞ 5.7K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity-approved Go API consistency review found no parity issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants