You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Functions to run a remote MCP server for Twilio API tools
4
-
5
-
## Pre-requisites
6
-
7
-
### Environment variables
8
-
9
-
This project requires some environment variables to be set. A file named `.env` is used to store the values for those environment variables. To keep your tokens and secrets secure, make sure to not commit the `.env` file in git. When setting up the project with `twilio serverless:init ...` the Twilio CLI will create a `.gitignore` file that excludes `.env` from the version history.
10
-
11
-
In your `.env` file, set the following values:
12
-
13
-
* ACCOUNT_SID
14
-
* AUTH_TOKEN
15
-
* API_KEY
16
-
* API_SECRET
3
+
Functions to run an MCP server for Twilio API tools
17
4
18
5
## Create a new project with the template
19
6
20
7
1. Install the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart#install-twilio-cli)
8
+
9
+
Recommended method, homebrew:
10
+
```shell
11
+
brew tap twilio/brew && brew install twilio
12
+
twilio login
13
+
```
14
+
21
15
2. Install the [serverless toolkit](https://www.twilio.com/docs/labs/serverless-toolkit/getting-started)
twilio serverless:init example --template=mcp-server &&cd example
31
25
```
32
26
33
-
4.Start the server with the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart):
27
+
4.Set environment variables
34
28
35
-
```
29
+
This MCP server uses API keys to authenticate the Twilio API requests. A file named `.env` is used to store the values for those environment variables.
30
+
31
+
In your `.env` file, set the following values:
32
+
33
+
* API_KEY
34
+
* API_SECRET
35
+
36
+
ℹ️ You can generate a new API key in the [Twilio Console](https://www.twilio.com/console/project/api-keys)
37
+
38
+
5. Start the server with the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart):
39
+
40
+
```shell
36
41
twilio serverless:start
37
42
```
38
43
39
44
ℹ️ Check the developer console and terminal for any errors, make sure you've set your environment variables.
40
45
46
+
6. Test your local MCP server using the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector)
47
+
48
+
```shell
49
+
npx @modelcontextprotocol/inspector
50
+
```
51
+
52
+
For local testing, use the following configuration:
53
+
54
+
***Transport Type**: Streamable HTTP
55
+
***URL**: http://localhost:{port}/mcp
56
+
57
+
ℹ️ When testing the protected /mcp endpoint locally, no authentication header is required.
58
+
41
59
## Deploying
42
60
43
-
Deploy your functions and assets with either of the following commands. Note: you must run these commands from inside your project folder. [More details in the docs.](https://www.twilio.com/docs/labs/serverless-toolkit)
61
+
Deploy your functions with the following command. Note: you must run this command from inside your project folder. [More details in the docs.](https://www.twilio.com/docs/labs/serverless-toolkit)
44
62
45
63
With the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart):
46
64
47
-
```
65
+
```shell
48
66
twilio serverless:deploy
49
67
```
50
68
69
+
### Testing your MCP server
70
+
71
+
ℹ️ We're aware of a reported issue with the MCP Inspector project and the authentication header. You'll need to use your MCP client to connect to your deployed MCP server.
### Code samples for generating a Twilio signature
81
+
82
+
Learn more about the use of `x-twilio-signature` header for executing `protected` Functions. https://www.twilio.com/docs/serverless/functions-assets/visibility#protected
83
+
84
+
The sample code below assuming that the following environment variables are set:
85
+
* TWILIO_AUTH_TOKEN
86
+
* TWILIO_BASE_DOMAIN
87
+
88
+
ℹ️ As the generated signature depends on the full Function endpoint that you are executing, and the URL includes the set of services (e.g. `/mcp?services=PhoneNumbers` vs `/mcp?services=Messaging`), you will need to generate a valid signature every time you update any part of the URL. We recommend dynamically generating the signature whenever you initialize the MCP client configuration with your Twilio MCP server.
#### npx with [`twilio-signature-cli`](https://www.npmjs.com/package/twilio-signature-cli)
152
+
153
+
This CLI tool makes it easy to generate Twilio signatures for webhook validation without writing any code. It's perfect for testing and debugging Twilio webhook integrations, or for generating signatures in automated scripts.
Use the querystring parameter `?services=` to specify a set of tools based on the needs of your MCP client. Set multiple services by passing multiple `services` key/value pairs.
177
+
178
+
**Examples:**
54
179
55
-
Header: x-twilio-signature
180
+
*`/mcp?services=Voice`
181
+
*`/mcp?services=Messaging&services=PhoneNumbers`
56
182
57
-
@TODO: Code samples to generate x-twilio-signature
183
+
**Available services:**
58
184
59
-
Available services
60
185
* Messaging (default)
61
186
* Voice
62
187
* VoiceAddOns
@@ -77,8 +202,8 @@ Available services
77
202
78
203
## Security recommendations
79
204
80
-
This remote MCP server function will provide Tools to your LLM that provide access to your Twilio account. We recommend the following considerations when giving clients access to your server:
205
+
This MCP server function will provide Tools to your LLM that provide access to your Twilio account. We recommend the following considerations when giving clients access to your server:
81
206
82
-
- Always set the `requires_approval` field to ensure that there are no unintended actions taken within your account.
207
+
- Always set your MCP client to require tool approval to ensure that there are no unintended actions taken within your account.
83
208
- Use scoped permissions for your Twilio API Key. Not all endpoints support scoped permissions, but some do. See https://www.twilio.com/docs/iam/api-keys/restricted-api-keys for more information about which actions are supported per API Service.
84
209
- To ensure privacy, do not use other MCP servers in conjunction with your Twilio MCP server.
0 commit comments