Cursor API Emulation

Cursor API Emulation

I've been following NVim development despite don't having time to adopt its usage (it needs some time to learn the keybindings). Despite that, there is a really interesting project to make a plugin that can emulate Cursor API to be able to use the paid subscription with something that is not a VsCode fork.

The dude behind it opened a bug bounty for it and announced it on Reddit so I decided to take a look. I'm really against these companies like Cursor that forces you to be behind their environment when the added value is the service they offer behind it. I understand the business logic behind it but it is still a bit of a crap. Honestly, I don't expect the bounty itself, I just want to contribute to a community of a tool that I don't eve use lol

Here is the issue with the bounty

Starting

Actually part of the code was already reversed some months ago, here. The main challenge is to gather the .proto files used for the gRPC communication. One of the protobuf files is extracted here.

@S1M0N38 did the basic proxy MITM in this comment already but he missed the full flow as some of the requests that Cursor is performing are not proxied if you use the VsCode proxy setting.

The approach I wanted to take was using the local capture feature of MitmProxy to realistically capture all the traffic from Cursor. This worked as a charm, having the main logic of the tab autocompletion done in the StreamCpp request.

You can read the full explanation in the Github issue, the investigation is still ongoing. Fore now I want just to focus on what I've learned and I don't want to miss for the future rather than the actual job done for the analysis.

New knowledge

After having clear that the requests were correctly capture I needed a way to decode the gRPC flows to gather some examples for the plugin development.

For that I need the .proto specifications. Luckily we already had some and more luckily the StreamCpp request/response is there too.

The idea is to play around with the tab-completion feature and check what that (or other) requests are sending, live.

For that, I built a small script that will display on the terminal (and log) the decoded gRPC communication. But... It was not that easy.

MitmProxy Limitations

The local interceptor in mitmproxy is just available via Brew for MacOS. This is incompatible with some scripting features in which we need to use the Python environment that ships with MitmProxy. For that, we need the PyPi version, which is not signed and cannot intercept local applications...

A workaround can be done. For example, we can intercept the flow with the local interceptor, save it and parse it afterwards. But I wanted a "live-view" of the requests. So... I jumped to Windows (don't judge me).

Compiling .proto files

Extracting the proto files is the hard part, but having them and compiling is kinda trivial.

protoc.exe --python_out=. aiserver.proto

More things I learned

There is a pretty fast Python package and project manager written in Rust: uv

It's also interesting how the Cursor client is saving the previous autocompletions to save tokens. It even save the things you erased:
Pasted image 20250415125232.png