Skip to content

Conversation

@zinodynn
Copy link

@zinodynn zinodynn commented Nov 18, 2025

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

  • feat: Forward chat input variables to MCP server via _meta

    • Enables passing additional variables from chat request inputs to MCP servers, facilitating use cases like identity verification and permission control.
  • feat: Support MCP protocol-reserved _meta parameter in tool invocations

    • Adds the _meta field to CallToolRequestParams to comply with the MCP specification, enabling transmission of metadata such as progressToken or identityToken.

These changes improve flexibility for MCP-level business logic, allowing for more fine-grained control and context-aware processing based on upstream chat request details.

References:

Screenshots

Before After
sql execution in MCP cannot be authenticated The functions can be expanded by customizing parameters
32765fe0b941c70ffb5cad795c14777

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 18, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zinodynn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the functionality of Multi-Chain Protocol (MCP) tools by allowing the forwarding of extra parameters, referred to as 'inputs,' from chat requests. This new capability provides a robust mechanism for implementing advanced business logic within MCPs, such as user authentication and fine-grained access control, by leveraging contextual information from the initial chat request. The change improves the overall adaptability and power of the tool invocation system.

Highlights

  • Enhanced MCP Tool Invocation: Introduced the capability to pass additional inputs parameters from chat requests directly to Multi-Chain Protocol (MCP) tool invocation methods.
  • Improved Flexibility: This change enables more flexible and context-aware processing within MCPs, supporting use cases like request-side identity verification and granular permission control.
  • Conditional Input Passing: The inputs are conditionally passed to MCP tools, ensuring that only relevant tools receive these additional parameters, and are merged conservatively to avoid overwriting existing tool parameters.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the 💪 enhancement New feature or request label Nov 18, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an inputs parameter to the MCP tool invocation methods, enabling additional variables from chat requests to be passed to MCP servers. This is a valuable enhancement for implementing features like request-side identity verification and permission control. The changes are well-implemented, propagating the new parameter through the necessary layers from fc_agent_runner to ToolEngine and the base Tool class. The use of introspection in the base Tool to conditionally pass the inputs parameter is a good design choice for flexibility. I have identified one high-severity bug that could cause a runtime error and one medium-severity suggestion for improving exception handling. After addressing these points, the PR should be in great shape.

zinodynn and others added 7 commits November 18, 2025 10:48
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Support the protocol-reserved `_meta` parameter for tool invocations, enabling metadata (e.g., progressToken, identityToken) transmission as specified in MCP spec.

See: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/docs/specification/draft/basic/index.mdx#general-fields
zinodynn

This comment was marked as outdated.

@crazywoola crazywoola requested a review from Nov1c444 November 20, 2025 03:18
@zinodynn
Copy link
Author

zinodynn commented Nov 21, 2025

Reference my approach to pass input parameters from chat requests to MCP tools, as outlined below:

  1. Create an identityToken using the app's input parameters, then save and publish it.
image
  1. Modify the MCP server code, and receive the identityToken params:
export async function executeSqlToolHandler(
  { sql }: { sql: string }, 
  _extra: any // Additional parameters from chat request
) {
  const connector = ConnectorManager.getCurrentConnector();
  // Retrieve `input` params from the request via:
  // const identityToken = extra._meta?.identityToken;   <---  receive params
  try {
    // ... Use the `sql` parameter ...
  }
  // ...
}
  1. Send a chat request (example curl command):
curl --location 'http://localhost:5001/v1/chat-messages' \
--header 'Authorization: Bearer app-xxxxxx' \
--header 'Content-Type: application/json' \
--data '{
    "inputs": {"identityToken":"eyJhbG...."},
    "query": "Query today'\''s sales orders?",
    "response_mode": "streaming",
    "user": "abc-123"
}'

@zinodynn
Copy link
Author

@Nov1c444, to prevent every MCP from receiving the parameters, would it be a good idea to distinguish parameters in inputs using dot-separated notation (e.g., .)? For example, create a parameter like mysql-mcp-server.identityToken in inputs to pass it specifically to the mysql-mcp-server MCP. This way, other MCPs won’t receive the identityToken parameter. If this makes sense, I’ll proceed to work on it.

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

Labels

💪 enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants