Skip to content

My VS Code Gained a Superpower- Taming LangChain with Live Context

Table of contents

Open Table of contents

Introduction: Drowning in Documentation Tabs

The most important property of a program is whether it accomplishes the intention of its user. > — C.A.R. Hoare

I was there again. Pinned in the crossfire between ambition and documentation. My mission, which I had chosen to accept, was to build a simple but smart chatbot using Python and LangChain. The goal: a weather bot that wasn’t just a dumb command-line tool. I wanted it to be clever, to understand location as a core context, and to provide genuinely helpful weather information.

LangChain is a fantastic framework, a powerful Swiss Army knife for building with Large Language Models (LLMs). But it moves at the speed of light. The tutorial I followed last month? Ancient history, leading to ImportError because a class had been moved. The blog post from two weeks ago? Already missing a crucial new parameter, causing a TypeError that had me questioning my own sanity.

My screen was a familiar mosaic of despair: a dozen browser tabs spanning the official LangChain Python docs, a half-dozen GitHub issues with conflicting advice, a few Stack Overflow questions with no accepted answers, and my VS Code window, feeling more and more isolated from the world of current information. Every time I tried to write a line of code, I had to Alt+Tab back to the browser, re-read a section, and try to stitch together the new coding patterns. My “flow state” was a distant memory.

The Glimmer of Hope: Discovering the Model Context Protocol

I knew what the problem was. My LLM assistant, for all its brilliance, was working from a memory of the internet that was months, if not years, old. It was trained on a static dataset. It couldn’t see the brand-new documentation page I was staring at. It needed a way to get real-time, relevant information—the very context I was struggling to manually feed into my brain.

This is when I stumbled upon a beautifully simple concept: the Model Context Protocol (MCP). It’s a protocol designed to do exactly what I needed: create a channel to feed live, structured context directly to language models from within your development environment. Instead of the model relying on old training data, it could now access fresh, curated information on demand.

The idea felt revolutionary. What if my AI assistant could read the same documentation I was reading, at the same time I was reading it? My gateway to this new reality was an unassuming server in a GitHub repository: Fetch.

Setting Up the Bridge: The Fetch MCP Server

The Fetch MCP server is a lightweight, local server that acts as a bridge between the live web and your LLM. It enables an LLM in your editor to read, or “scrape,” information from a website you specify.

The setup was the most refreshing part. No complex configurations, no wrestling with dependencies. I just set it up on my VS Code. A few commands in the terminal and I was ready to go.

Here’s how simple it was:

# 1. Install using pip
pip install mcp-server-fetch

# 2. After installation, you can run it as a script using:
python -m mcp_server_fetch

That’s it. A server was now running locally, ready to act as a periscope for my AI assistant, allowing it to peek at the live internet on my command.

The Breakthrough: From Frustration to Functional Code

This is where everything changed. With the Fetch MCP server running, my workflow was transformed. I went back to my weather bot project.

Before, my code was a mess of trial and error based on outdated examples. I was trying to manually implement a BaseTool class, something like this:

# The "Before" Attempt - Based on old examples
from langchain.tools import BaseTool
import requests # Hypothetical weather API

# This approach is verbose and might use deprecated patterns.
class WeatherTool(BaseTool):
    name = "get_weather"
    description = "Useful for when you need to get the current weather for a location."

    def _run(self, location: str):
        # ... logic to call a weather API ...
        # Is this right? How do I handle async? How do I add arguments correctly?
        return f"The weather in {location} is sunny."

    def _arun(self, location: str):
        raise NotImplementedError("This tool does not support async")

# ... How do I integrate this into an agent again?

This code felt clumsy, and I wasn’t confident it followed the latest best practices.

Now, with my MCP server running, I simply pulled up the official LangChain page for custom tools. Then, back in VS Code, I wrote a new kind of prompt for my AI assistant:

@context([https://python.langchain.com/docs/modules/tools/custom_tools](https://python.langchain.com/docs/modules/tools/custom_tools))
Based on the exact content of this page, show me the modern Python code to build a simple LangChain agent with a custom tool named 'get_weather' that accepts a string 'location'. Use the @tool decorator.

The response was instantaneous and magical. The LLM, using the Fetch server to read the provided URL in real-time, gave me the exact code snippet I needed. It was clean, concise, and used the modern decorator syntax I had seen glimpses of.

This is the beautiful, functional code it produced:

# The "After" Result - Clean, functional, and modern!
import os
from langchain_openai import ChatOpenAI
from langchain.agents import tool, AgentExecutor, create_react_agent
from langchain import hub
import requests # To call a real weather API

# 1. The custom tool, created with a simple decorator.
@tool
def get_weather(location: str) -> str:
    """Useful for when you need to get the current weather for a specific location."""
    
    api_key = os.environ.get("OPENWEATHERMAP_API_KEY")
    base_url = "[http://api.openweathermap.org/data/2.5/weather](http://api.openweathermap.org/data/2.5/weather)"
    params = {"q": location, "appid": api_key, "units": "imperial"}
    
    response = requests.get(base_url, params=params)
    if response.status_code == 200:
        data = response.json()
        main = data['main']
        weather_desc = data['weather'][0]['description']
        return f"The weather in {location} is {main['temp']}°F with {weather_desc}."
    else:
        return "Sorry, I couldn't retrieve the weather for that location."

# 2. Set up the agent with the new tool.
# Make sure your OPENAI_API_KEY is set as an environment variable
llm = ChatOpenAI(model="gpt-4-turbo", temperature=0)
tools = [get_weather]
prompt = hub.pull("hwchase17/react") # Pull a standard agent prompt

agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# 3. Run the agent!
agent_executor.invoke({"input": "What's the weather like in London?"})

The friction was gone. The roadblock that had cost me hours of frustrating searching was resolved in seconds with code I could trust—and copy and paste directly into my project.

Key Takeaways:

  • Live Context: Injecting up-to-date documentation directly into your workflow cuts down wasted time and cognitive overhead.

  • Simple, Powerful Setup: With just a few commands, Fetch MCP transforms your IDE into a real-time collaboration platform.

  • Collaborative Future: Embrace the shift from static codex to an interactive development partner drawn from the latest data.

Conclusion: Beyond Completion, Towards True Collaboration

My experience was more than just a productivity hack; it was a glimpse into the future of software development. We’re moving beyond simple autocompletion and into a world of truly collaborative creation with our AI tools. The LLM is no longer just a clever parrot of its training data; it’s a dynamic partner that can reason about fresh information.

By giving our AI assistants controlled, real-time access to specific information—whether it’s the latest documentation, a new API spec, or even a thread from our team’s issue tracker—we eliminate the single biggest bottleneck: outdated context.

Tools like the Fetch MCP server are the missing link. They are fundamental pieces of a new, more intelligent development environment that respects the context of now. They transform our IDEs from simple text editors into active partners in the creative process. In the grand symphony of code, having a partner that can read the same sheet of music is not just helpful—it’s game-changing.