Full MCP support in Layla
- Layla
- Oct 1
- 4 min read
Updated: 14m
In the previous two articles (link, link), we introduced Agents in Layla and then dived deep on how they work.
In this article, let's explore the final layer of Layla Agents - Full MCP support.
MCP
MCP stands for Model Context Protocol - it is a way for LLMs to interact with external services via a predefined protocol through a combination of natural language and structured outputs. For more information, see https://modelcontextprotocol.io/docs/getting-started/intro
MCP works in general by putting the signature of each possible tool an LLM has access to in their system prompt. An LLM should intelligently determine which tool to call during the conversation and continue the conversation with the result of the tool call.
Layla Agents & MCP
Previously, Layla's Agents are triggered by a combination of keywords and traditional ML technique such as intent detection. This is the default setting in Layla. This is because on mobile, the context is limited, and injecting all the possible tools in the system prompt uses much of our valuable context. Additionally, smaller models that run on mobile may not always determine the best tool to call, so traditional ML techniques actually have an advantage here.
Layla supports fully allowing the LLM to choose which tool to call. Let's see how this works.
The Layla: Introspection agent is an example of how to use MCP Tool calling in Layla. Start by searching for the tool name in the Agents mini-app and editing it. This will bring up the editing popup where you can see how it works internally.

The main thing you will notice is that all the triggers are using the special "Layla Tool Trigger" we mentioned in the previous article. This trigger tells the Agent to inject all the possible tools' signatures into the system prompt. In this example, the tools signatures of Layla Apps Info, Layla: Clear Caches, and Layla: Operating Stats are injected in the system prompt.
The Tools Flow section simply contains one tool: Layla Tool Call, with the input being {{match$1}}. Leave this as is, the tool call expects this format. There is no need to add other tools either, because the LLM will determine when to call each tool listed in the triggers section. The output of each tool is automatically injected into the LLM's context, and the LLM may decide to chain call other tools as needed.
To change the list of tools, you can edit the Introspection Agent and remove the triggers. Then add new ones. In the dropdown list, you can select all tools available in Layla.
Note: there is a balance between selecting the number of tools here; you don't want to overwhelm the LLM to the point it confuses which tool to call.
A recommended method of organising is to group your commonly used tools into one agent, then attach this agent to a new character that you create. This gives the character a clear specific goal, which will reduce hallucinations greatly.
Connecting to external MCP Servers
Layla supports connecting to external MCP Servers, whether it be servers provided by known organisations, or an MCP Server running on your PC!
Layla provides a supporting mini-app called MCP Support to help you automatically discover and configure external MCP Servers.

You can see a list of commonly used MCP Servers here: https://github.com/modelcontextprotocol/servers/tree/main
The list includes MCP Servers from numerous well-known organisations, including code which to host your own if you wish.
A well-implemented MCP server will have a tools discovery endpoint. Let's use the public Fetch MCP server as an example. This is a public MCP server that performs web-scraping functions to enable the LLM to read the contents of a webpage.
We start by opening the MCP Support mini-app in Layla, and entering the remote MCP server URL:

Tap on Discover Tools, this will initiate the connection to the MCP server, and query it for a list of available tools. In this case, there is only one tool called "fetch", and it will be disabled after the MCP Server responds.
Select the tool (this will highlight it green) and tap Create Agent. This will create a new Layla Agent with your selected tool.
You will be directed to the Agents mini-app with a new agent named "New Agent" that is created for you. Feel free to edit the name and description!

Leave all other parameters (Triggers, Tool Flow, etc.) unchanged. This is all configured for your correctly.
Now you can enable the agent by creating a new character and attaching this Agent to it! (Note, we create a new character here because we don't want this new agent to conflict with existing ones in Layla. You can also disable the existing Web Search Agent in Layla as well; the choice is yours.)
Go to the Advanced tab in the character creator

Tap Select Agents to bring up the popup

Select the Fetch agent; it will appear in the list

After that, save your character! We will use a duplicate of Kip in this example.
Kip will initiate the MCP tool call when prompted:

After the MCP tool call, Kip will respond to your request and notice it actually responds in Kip's personality! This is what we mean by personalised. Your own characters will respond to your request with tool calls, in your configured personality.

Here is the MCP JSON you can download and import it into Layla:
Comments