Your Plugin's Second Service: Architecture for Integrations That Grow
Read full transcript 37 segments
-
Hi, everyone. Once again, I'm Eugenie. I worked in software development for more than 15 years, and eight of them were at JetBrains working on IntelliJ IDEA and on Upsource, which is a code review tool. Then I worked on a few web projects. And in 2019, I started my own plugin. The idea of it came from the code reviews. I did every day because I worked as a team leader that time. It was kind of pain to do this in Bitbucket web interface. So it started as a simple pull request plugin for Bitbucket Cloud. It was one plugin, the one service. Today, the same code base shares four plugins for five services with about 7,000 paid seats. But I can say that only first two plugins are paid, other two are free.
-
Five services because Bitbucket Cloud and Bitbucket Data Center have the same name, but they, in fact, complete a different product with different APIs and features and even color schemes. All my plugins today share one code base. And I will show you how the design changed with each new service and why most of the logic became finally easy to test and what happens when two plugins from one code base meet in the one IDE. And at the end, I will show one of the newest features of my plugins, MCP Tools for AI Agents. And I will show how any plugin can add its own tools to the MCP server that is built into the IDE. The first request for a second service was Bitbucket Server, which is now called Bitbucket Data Center. As I mentioned, it's the same brand, but a different product with its own REST API and features.
-
For example, Bitbucket Server can reopen a decline pull request and Cloud can't. But on the other hand, Cloud lets you give a reason when you decline. And of course, every server installation can run a different version. So first, I split the code into a common part and a part for each service. Very simple design. And the same was a few shared types, like code review service instance and pull request plus the API client, where the two products worked differently, the common code asked the service. And when a feature existed only in one product, the common code still had to know about it. For example, Cloud has tasks, the concept of tasks, and server has blocker comments. Their ideas were very similar, but details, how they work, were really different.
-
So the common code supported both and asked the service which one it had. It worked, but of course, the common code was full of things that belonged to only one service. Then came GitLab, the service. And with even more differences, here are two of them as examples, diffs and people. In Bitbucket, comments are attached to a single commit or to a range of commits. But GitLab saves a version on every push, even after a forced push which may fully rewrite history. And comments belong to that version, not to commit. Then people. Bitbucket has reviewers with a status, very simple. But GitLab has other roles, such as assignees and also approvals from other team members, such as code owners.
-
So finally, I introduced the following rule. The shared part holds what makes sense for more than one code review service, even if only one service supports it today. Like notifications are now supported for Bitbucket Cloud only, but of course, notifications make sense for any code review service. On the other hand, those GitLab versions I mentioned are very specific, and they stay in the service-specific part. Also, GitLab differences needed their own dialogues and panels, and the old theme had no good place for UI. The old theme cracked in two places. First, GitLab works with models in its own way. For example, it stores versions which I didn't want to add to a shared model. And second, GitLab's dialogues and panels could only go to the service instance I showed you, so it kept growing.
-
So I moved the theme up from the API to the business logic in two steps. First, the model. The model is the data in memory that the UI shows, like the pull request list, an open pull request and its comments. The shared model got an extension for each service where they can store service-specific data. Then the operations moved into so-called use cases. A use case is shared code. It reads the model, calls the service, and writes the result back. Each service has a use case extension for its own part. The shared code stopped calling the API directly. Only use case extension called it. That fixes the first crack, but the dialogues and panels I mentioned got their own place as well. More on that in a minute. From here, the code on the slides is simplified.
-
Here are two common operations. Where services agree, the use case does the work by itself. For example, a draft is deleted without calling the service at all and removing deleted comments from the model is the same for every service. So you can look at the slide a little bit. And where the service differ, the use case extension does the work. For example, when you resolve a comment, GitBucket keeps the flag on the first comment. So the thread... Sorry. The first comment of the thread. So it's extension updates on that one comment. And GitLab keeps the flag of every comment in the discussion, so it's extension updates all of them. It's a very simple example just to demonstrate quickly. Of course, there are many other differences between services. So the services differ in how they change the model now, not only what they send to the server.
-
That's why the C moved above the API clients. And later, when GT came, which is another one-mode code review service, its proof of concept didn't change any code in the shared part at all. When the C moved, the code also split into two layers. This idea came from clean architecture. Probably some of you heard about this. I knew it from Web Application World, so I decided to experiment a bit and try it here. The IDE layer has everything built on the C, the IDE layer has everything built on the IntelliJ platform. Actions, UI, settings, extensions, like tool windows, for example. And the use cases and the mode and models went to the core layer. And here is the rule. Every non-trivial behavior goes into the core, where tests can easily reach it.
-
The core may use basic IntelliJ classes as well, like project or logger or utility classes or bundled libraries, but for anything else, it declares an interface. That's just a convention. The build doesn't check it, at least for now, but it won't. The IDE layer calls the use cases and implements the interfaces of the core. Also, service-specific protocols like Bitbucket and GitLab REST APIs also live in the IDE layer, so the core never sees them. In tests for use cases, those interfaces get Mockito mocks, as you can see on the slides. As I mentioned, we still need a light test project because the core uses projects. So we use allied features provided by the platform.
-
And here is Bitbucket resolving a comment. The example from before, we put a comment and it's replying to the model. We run the use case and check two things per the model. And second, the API got exactly one call. Now let's see how one codebase becomes several plugins. Each layer has two interfaces, one for the whole plugin and one for each service. Here they are in Bitbucket plugin, which has two services, cloud and server. In the IDE layer, Bitbucket plugin extension is the entry point for the plugin. It's registered in the IDE through an extension point of my own and everything else comes from it. The plugin settings, the core extensions and a plugin service extension for each service.
-
A plugin service extension has the UI that differ between the services like dialogues and panels, for example, login dialog or merge pull request dialog. Now the core, it declares core extension and the IDE layer implements it. For Bitbucket, it's Bitbucket core extension. It gives the core what it needs from the IDE, like storage, for example. And it has core service extensions for each service. Each of them gives out that services model and use case extensions I mentioned before. Here are two extensions of one service, Bitbucket and cloud. The core one creates cloud's model extension and gives out its use case extensions. Like the one that resolves a comment, it also answers some questions about the service.
-
For example, that cloud supports notifications. The IDE layer one creates cloud's own dialogues, like login and merge and renders cloud's Markdown in comments, in descriptors by providing specific HTML content renderer. So everything specific to Bitbucket Cloud starts from these two classes. Now let's consider installation of two of these plugins in one IDE. As we know, each plugin has its own class loader. So shared code is loaded twice and the two copies actually never meet. It's the same as when several plugins bundle the same library. There is another option actually to create a base plugin with the shared code and make the other plugins depend on it.
-
Then there is only one copy and nothing clashes. But the problem here is versions. A user can update the base plugin without the other plugins, for example, or vice versa. And today, plugin can't say which version of the base it depends on. It can only declare the dependency but not on the specific version. So I experimented with both options and finally choose the first one. So each plugin now ships on its own and it also looks much more straightforward for users. But the price here is names. The IDE finds a lot of things by name and these names are global. ID services by their class names, actions, data keys, tool windows, settings keys, etc. For example, these two goals on the screen looks the same, but the IDE much longer than the IDE matches data keys by their name.
-
So both plugins use the same data key. And then GitLab's action can get the bucket's object from the context, a different class, but with the same name. Because the class loaders are different, the class is still different. So it fails with class cast exception. On the other hand, there is no such problem with key, not data key, but just key. Key.create because keys with the same name aren't equal. So everything the IDE finds by a string needs the plugin prefix. The prefix comes from the build. Each build set, each plugin's build set a few tokens. The prefix, the plugin ID, even the word for a pull request because GitLab call them merge requests, not pull requests. The shared models are compiled once and packed into every plugin.
-
So the build replaces the tokens inside each plugin's jar after the main build. In plugin XML, this gives every action its own ID. We also need those values at runtime, so the build also writes them into a small property file. The shared code loads this file with its own class loader, though each copy finds its own plugins file and gets the right values at runtime. IDE services need something else. Their key is the class name and a token can't rename a class. At least it's much more difficult. So the shared code declares no IDE services. Instead, each plugin declares a holder. All shared IDE services live inside that holder in a map from class to instance. And because the holder is a real IDE service, each plugin gets its own coroutine scope and everything inside is disposed when the plugin unloads.
-
Of course, it's a workaround and it doesn't look beautiful. I'd rather not need it, but it's both the simplest way for me, so I used it. Here's how I released these plugins. A fix in shared code means releasing every plugin, of course, and a fix in one plugin in some plugins own code means releasing only that plugin. The major version is shared and each plugin has its own minor version. Finally, the themes helped where I didn't expect the AI agents. My tools for AI agents became one more client for the core, next to the UI. JetBrains IDEs have a built-in MCP server.
-
You turn it on in the settings and the IDE sets up the agents you have. Claude Code, Codex, Cursor, Junie, Copilot, it comes with the IDE's own tool. For example, an agent can find a symbol, check a file with IDE inspections, or even rename something with refactoring. There are also many other tools the IDE provides out of the box. And any plugin can add more tools to the same server, so you don't need to implement the protocol or open a port. The IDE does all of that. (Silence) To add a tool, you need a dependency on the bundled MCP server plugin. A few lines of XML and a class. With plugin model version 2, if you already tried it, the module's XML also has to declare the dependency on the MCP server plugin.
-
Like this on the screen. (Silence) And each tool in the class, here is the tool set class. Each tool in the class is a suspend function with two annotations. Its name and its description. Inside, you get the project from the Coroutine scope, Coroutine context, sorry, for an error that the agent should read, you call MCP fail with a message. (Silence) The server builds the JSON schema from the Kotlin signature and the agent gets it. The names and the descriptions come from the annotations stuff like types from Kotlin. Enums give the agent a closed list of values to choose from.
-
The server also adds a project path to every tool, so the agent can say which open project the call is for. By the way, a nullable type alone doesn't make a parameter optional. It needs a default value, equals null or another value. And agents sometimes also send an empty string instead of leaving a parameter out, so I treat blank string the same way as null values. Here is one of my tools. A tool can return a string or a serializable class and hints tell the agent if a tool only reads or deletes something. Or talks to the outside world, like in our case. For a long call, it's good to use a timeout or even show progress, and it's worth to make it cancelable.
-
You can't know for sure how long the agent will wait. Also, when you need to use a position, for example, line or offset in code, sometimes agent miscount and pass-through values. So you'll see it in a minute on another slide. Regarding tests, at least for now, the platform's own test infrastructure for MCP is internal, so it cannot be used by plugins. So I just test the logic behind the tool as in other places of my code. (Pause) Three more things about the API. I ran and I ran into each of them. To turn tools on and off, there is isEnabled function, but it's checked only once when the service starts. So it can depend on currently opened projects or on state of those projects.
-
(Pause) Another thing is a router mode, which is a setting of the MCP server. In router mode, the agent sees only a short list of tools, plus one tool, the trans that can run any tool by name. And from the platform 2026.3, there is alwaysIncluded function, which keeps your tools on the short list. And another thing that you cannot add prompts or resources, so descriptions are the only way to guide the agent, at least for now. (Pause) Now my plugins. Tool names are more... Yeah, tool names is also global namespace. The agent gets one list from the whole IDE with the built-in tools and every plugin's tools.
-
So you need to give your tools a prefix. In my case, with several plugins from one code base, it also means the tools can be declared in the shared code. Or two plugins would offer the same names. The shared base class has only the plumbing here. It creates the MCP use case, runs the call, and turns errors into messages for the agent. And each plugin declares its own tools with its own names. This also lets the tool differ a little. For example, GitLab tools say... (Pause) It was saying that the MCP server also has a tool provider API. MCP tools provider class interface for tools built in code at runtime. With it, I could declare the tools once and add the prefix dynamically, but then I'd have to write every schema by hand, and not generated from Kotlin in signatures.
-
And as you see sometimes, the tools are different anyway. The tool function does almost nothing. In fact, it cleans up the parameter and calls a use case in the core. It never calls the API itself. The MCP use case works like all other use cases. The shared part once and a use case extension for each service. It's important to say that it needs its own use case, though we already have use case for adding comments. Because, for example, the tools must work even when no pull request is open in the UI. And there are some other differences as well. (Pause) Here is Bitbucket Cloud adding a comment. "Agent miscount lines", as I mentioned.
-
So the tool also takes the text of the line and the extension rejects the comments if the text doesn't match. It's just an additional check. (Pause) So it creates the comment as pending, then the shared part puts the comment into the open pull request model if it exists. So it shows up in the IDE right away. The use case is tested like all other use cases with mock interfaces. Now let me show how the tools work. (Pause) Okay, here we have a simple pull request, which contains some code for computation average, and this code contains two bugs.
-
(Pause) We have a button to run review here, but I don't want to use it now because we don't have enough time. Instead, I will copy link, open terminal, and here we have Claude Code. And I'll write something quickly, review the pull request, add comments, and suggest fixes using the Bitbucket. (Pause) Okay, let's launch. Let's see what it does. Okay, first it called the Bitbucket get pull request tool to get the pull request details. By passing its ID and repository, it retrieved from the URL. It passed what to include, changes, discussions, and commits.
-
It's the custom protocol of the plugin. It's not a Bitbucket REST API because Bitbucket REST API contains many unnecessary stuff and difficult to use by agents. So next, it called Bitbucket get file diff to get the diff. It passed specific commit hashes and the file path. Okay, next it found two bugs. That's two bugs. And called Bitbucket add comments twice to add the comments with passing file path, commit hashes, and as I mentioned, the line content. (Pause) So it finished. Let's see what it reported. It created two pending comments.
-
One is about that we used the wrong sign here, and the other one is about missing typecast to double. Okay. (Pause) It's a window of the Bitbucket plugin. Here we can click finish review to request changes from the author. (Pause) Okay, the comments are submitted. (Pause) So thank you very much for your attention. If you have any questions, I'm happy to answer them. (Pause) Thanks a lot, Evgeny, for the nice presentation. I have millions of questions, but I will start putting one of the questions from the viewers on screen.
-
I think it was this one here. So, Autium asked, "In an age of AI coding, instead of such a co--" I think it's about basically your setup of having features separated and one base plugin or one base functionality. I think the question was around this, right? "Instead of such complicated layered abstractions, wouldn't it be easier to keep completely separate code bases and synchronize them using AI-agentic coding?" I'm also interested to answer. And I can put basically the next comment as well because it's related. "PS, we used that approach in Qodo for sync implementing things in plugins for JetBrains, VS Code, and VS Pro, and it seems to work." Do you have an opinion on that? Yes, probably yes. Honestly, I didn't try because I started my plugins long before the AI era. But I can say that AI agents works very well with the abstractions of that level because currently I write most of my codes and new features with AI agents.
-
And I guess it's not worth the approach at least. Sometimes when you need to review and check AI agents, it's-- anyway, it's easier to do in one code base than if you have, I don't know, five of them. (Laughter) I got a question that is a new question because in our team, Robert is the one who looked really into the version 2 modeling and stuff. So basically, from what I understand is basically you have core functionality, but it's really different between GitHub and Bitbucket and everything, and you need to adapt it, right? And you basically need some shared functionality, but then each service needs their really own specific handling. So would the new version 2 model help with that? Can you do different modules there? I don't know. It's basically a question to you, if any, and Robert, if someone has information on that.
-
By version 2 model, you mean plugin model version 2, right? Yeah, plugin model version 2, yes. OK. Honestly, I don't think it helps a lot because it mostly about-- as far as I understand, it mostly about optional loading of some parts of your plugin. So you can make some modules in the plugin that will load only if some dependencies exist. For example, I made it for mcp-server. If mcp-plugin is disabled, that part isn't loaded at all. And also, as far as I know, it's widely used in remote development mode when you need to load specific modules on the back end and other modules on the front end.
-
So plugin, in fact, is separated into parts. Yeah, so that's basically what I know, right? Yeah, exactly. It's about delivering a single artifact with multiple separated functionalities where you don't need to distribute multiple plugins, but a single one. And you can enable and disable functionalities according to available dependencies. Yeah, that's right. But the setup might be difficult initially, but when it's done, it might fit the scenarios with multiple implementations of multiple vendors and a common functionality. We are not pushing you into this model. We are just getting folks to know that this might be actually useful. Yes. I spent three days to migrate, but that was a long time ago.
-
Maybe there is better documentation today. Yeah, definitely. There is better documentation, better tools. And better support. Thanks, Jakku, for simplifying IntelliJ Platform Gradle Plugin. That's actually didn't... It wasn't me. It was the core team who contributed to this tool. I'm not the only developer. Yes, remember that. So I have more questions. I see no other questions on the... Wait, no other questions to you, but I got one. So you were talking a lot about the MCP tooling and adding basically functionality to the IntelliJ MCP server. And this is really easy. One of the things I'm constantly worried about when I see what people do with their agents and with skills and MCP servers is they put lots of skills into their user thing. And basically without realizing that the agent gets this into the context every time.
-
So with the MCP server, and you mentioned that it has this router mode, right? Where you don't show all the things, which is, I guess, one way to prevent this. This, you constantly have the problem between making it obvious to the agent that there is a tool that can be used and not overwhelming it, but still having a clear guidance, right? So let's say, thousand plugins on the JetBrains marketplace start adding MCP tools. And only a few, maybe five, right? That leaves us with something like 5,000 MCP tools in our server. What do you think happens then? How can we solve that? Oh, well, I think the router mode is a great idea here, but agents needs to discover tools by names, which I believe is supported in router mode. So in router mode, they see the names, but not all parameters, descriptions, et cetera.
-
I guess the names of MCP tools should be self-describing. For example, if all of my tools has Bitbucket or GitLab prefix, it's obvious that if you have GitLab in your prompt, probably, agents try to use those tools. Yeah. And also maybe pushing users to disable plugins they don't use makes sense. Yes, that's a good thing. So I was just wondering, right, because I wanted to do something about some content and I was wondering how we can answer that. I got a suggestion for you. So you were asking, or you were basically saying, okay, there's not a real good way to inject a prompt so that basically people who have installed your plugin, the agents they are using automatically know about your tools, they have to discover it. But what you could do is implement a simple action that creates a .agent something file.
-
And so basically that's what I do. I have basically a guideline, a small one. If you want to do something like that, go here and there's an additional markdown file, a markdown prompt that directs specifically to the tools that they are used. And you could implement an action that does that and creates it for the user, right, to make it easy to set up version control functionalities that uses the MCP server. That would be one idea that I use in the past. Yeah, that's a good idea. And actually I already used it because I have the button which starts the terminal automatically and puts the prompt inside it. So the prompt can be prepared with direct calls of necessary tools. But the API isn't rich enough. For example, I didn't manage to do the same with air. Yeah, yeah.
-
Okay. So, all right. Let me ask maybe how much time? We got two minutes left. All right. Let me ask one more question and then we can raffle off some more of the gifts. So you mentioned a base plugin as an option, right? And apart from the version differences, what else made it a bad fit for your plugin? What else apart from versions? Well, first of all, that's a dependency on a third party plugin. Users need to install look bad for users. Looks bad for users. They may forget what it's for. They may disable it accidentally. And so it just doesn't look good. For users, it's easy to just install one plugin and to use it. And also, it's harder to use by paid plugins because finally in such structure, most of the code of a paid plugin would sit in a free base plugin.
-
And also the names that the other plugins call cannot be obfuscated, for example, and license cannot be checked in the free plugin. So, I think a base plugin approach can be used by free plugins that change rarely. So, they wouldn't have problem with versions. They can just release some stable core plugin once and then depend on it. All right, Yevgeny. Thank you very much for your presentation, especially I think the second part about the MCP server and tools sparked a lot of interest and it really shows that we need to bring out more content about this, how to use it and how to do it properly and how to ensure your work with the agent goes right. Thanks a lot again for a presentation. It was really, really good to have you here. Okay, thank you so much. Thanks a lot.
No summary available yet.
View original episode ↗