/mcp-tutorials

How to integrate tool results (e.g. web search) directly into MCP?

Discover how to integrate tool results like web searches directly into MCP. Our guide covers updating context, system instructions, and setting constraints for optimal output.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to integrate tool results (e.g. web search) directly into MCP?

 

Step 1: Understand the MCP Structure

 

The Model Context Protocol (MCP) is a framework that helps you organize and structure how context is provided to language models. It involves several components:

  • System Instructions: Define the role and expertise of the model.
  • User Profile: Contains details like name, preferences, and goals.
  • Document Context: Includes any knowledge base or documents the model should be aware of.
  • Active Tasks/Goals: Lists the current objectives or to-dos for the model.
  • Tool Access: Specifies what external tools or APIs the model can utilize, like web search or database access.
  • Rules/Constraints: Sets boundaries on what the model should or shouldn’t do.

 

Step 2: Determine the Integration Requirements

 

Before you integrate tool results into MCP, you need to identify:

  • Which tool or API results need to be integrated? (e.g., web search results)
  • How these results will be used within the context? (e.g., supporting data for user inquiries)
  • The specific MCP components where these results should be included. (e.g., adding search results to Document Context)

 

Step 3: Prepare the Tool for Integration

 

  • Access the API or Tool: Ensure you have proper access and credentials to the tool or API you're going to use.
  • Ensure Data Compatibility: Make sure that the data format from the tool is compatible with how MCP handles content.

 

Step 4: Modify MCP to Include Tool Results

 

Integrating tool results requires adjusting MCP components.

  • Update Document Context: Add retrieved data from the tool to your document context. Structure the results so they can be easily referenced.
  • Adjust System Instructions: If necessary, update system instructions to inform the model about the new capabilities or data it can access.
  • Revise User Profile or Active Tasks: If the new tool results influence user tasks or profiles, make the appropriate changes.

Example code to integrate web search results into the Document Context:


// Assuming searchResults is a variable containing the results from your tool
let mcpDocumentContext = {
  knowledgeBase: [
    ...existingDocuments,
    { title: "Web Search Results", content: searchResults }
  ]
};

 

Step 5: Implement Guardrails and Constraints

 

Whenever new data or tools are integrated, it's important to define what the model cannot do with this information:

  • Avoid Generating Specific Outputs: Set guidelines to prevent the model from using tool results inappropriately.
  • Domain-Limitation: Ensure the model stays within relevant domains when applying new results.

 

Step 6: Test the Integration

 

  • Conduct User Testing: Verify that the tool results are being utilized effectively within different contexts and use cases.
  • Monitor Model Outputs: Ensure that outputs remain accurate, relevant, and adhere to established constraints.

 

Step 7: Iterate and Refine

 

After testing, you may need to make changes:

  • Refine Context Updates: Based on how well the model is utilizing the tool results, adjust the context integration.
  • Adjust Constraints: If necessary, fine-tune the rules and constraints to better align with desired outputs and behaviors.

This process ensures that any tool integration enhances the model's functionality in a consistent and predictable way.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022