Skip to content

How execute local stdio mcp server with approval #25

@dantonini

Description

@dantonini

Hi folk,

I have a local mcp server that interacts with a database. The mcp has several tool functions, some of them are in read others in write.
I want to be able to:

  • or approval for all mcp tools
  • or approval only for write operations (or more in general way: per tool function approval).

What is working

mcpServer := agents.NewMCPServerStdio(agents.MCPServerStdioParams{
		Name:           "mcp-mysql",
		Command:        cmd,
		CacheToolsList: true,
	})

agent.
    AddMCPServer(mcpServer)

With this code the agent is able to use my mcp server without any issue but it executes the tool functions without asking for permission.

Looking at the code the only place I found something similar is hosted_mcp: https://github.com/nlpodyssey/openai-agents-go/blob/main/examples/hosted_mcp/approvals/approvals.go

I tired to use it in combo with mcp server but it seems that the hostedMcp methos is designed to work only with remote mcp servers

mcpServer := agents.NewMCPServerStdio(agents.MCPServerStdioParams{
		Name:           "mcp-mysql",
		Command:        cmd,
		CacheToolsList: true,
	})

agent.
    AddMCPServer(mcpServer).
    WithTools(
	agents.HostedMCPTool{
	    ToolConfig: responses.ToolMcpParam{
                ServerLabel: "mcp-mysql", <--- same name as the mcpServer instance
	        ConnectorID: "asd", <--- tried different values or ServerURL, without any luck
	        RequireApproval: responses.ToolMcpRequireApprovalUnionParam{
		    OfMcpToolApprovalSetting: param.NewOpt("always"),
	        },
	        Type: constant.ValueOf[constant.Mcp](),
	    },
	    OnApprovalRequest: approvalCallback,
	},
    ).

I looked around and found also: hooks, however they seem to be designed as "notification" system of events and not as control mechanism.

Then I started to dig into the code and debugged the flow:
if my understanding is correct to cover my use-case something is missing in the mcp_util.go file method InvokeMCPTool. Or maybe better extend the FunctionTool struct to support a tool approval callback.

Is there an already supported way to implement my use-case?

Thank you for your support

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions