The problem
One of my complaints about using AI code gen with Cursor has been its "backwardness"; it tends to use older versions of libraries. This sometimes means your generated code isn't as well-structured as it could be. It's why AI code gen has sometimes felt to me like working with a grumpy older senior engineer.
What we want is some way of telling Cursor (or AI code gen in general) to use the latest library versions and use the latest code samples. Of course, we could supply links to the library documentation ourselves as part of the prompt, but this is tedious, which means we're prone to forgetting it.
Wouldn't it be great to have a list of all the latest libraries and documentation and supply it directly to Cursor via an MCP server? That means, we'll always point to the latest version of the code and docs, Cursor will pick it up automatically, and someone else bears the cost of keeping the whole thing up to date. With such a service, we could always generate code using the latest version of libraries.
(Gemini)
The solution
As you've guessed, such a thing exists and it's called Context 7. Context 7 provides links to the latest version of over 49,000 libraries, everything from Next.js to Requests. It provides these links in a form that's usable by LLMs.
If you really wanted to, you could include these links via a prompt. For example, for Streamlit, you could use the results here in a prompt: https://context7.com/websites/streamlit_io. But that's inconvenient. You're better off using the Context 7 MCP Server and telling Cursor to use it in code generation.
How to implement it
There's a lot of advice about installing the Context 7 MCP Server on Cursor, some of it misleading and others wrong or out of date. Here's the easiest way to do it:
- Have Cursor running in the background.
- Go to this page on GitHub: https://github.com/upstash/context7
- Go down to the section "Install in Cursor" and expand the section.
- Click on the "Add to Cursor" button:
This should automatically add the Context MCP server to your installed MCP servers. To check that it has, do the following in Cursor:
- Click on the "Cursor" menu option, then click "Settings...".
- Click "Cursor Settings".
- Click "Tools & MCP".
Next, you need to tell Cursor to use Context 7 when generating code. You could do this on every prompt, but that's tedious. You're much better off adding a rule. The Context 7 GitHub page even tells you how to do it: https://github.com/upstash/context7?tab=readme-ov-file#-tips.
Using it
This is the best part, if you've added the MCP server and you've added the rule, there's nothing else to do, you'll be using the latest version of your libraries when you generate code. I've heard a few people comment that they needed to restart Cursor, but I found it works just fine.
The cost
Using Context 7 will cost you more tokens, but in my view, it's a price worth paying for more up to date code.
Who's behind Context 7?
A company called Upstash have created Context 7 and they're providing it for free. To be clear: I have no affiliation of any kind with Upstash and have received no benefit or reward from them.
Bottom line
Use Context 7 in your code generation.

No comments:
Post a Comment