Writing Functions
Here’s a simple example - a “Hello World” function that expects a name parameter in the request.
Everything defined in the Request interface must align with the parameters configured in the corresponding MCP interface.
interface Request { name: string;}
interface Response { message: string;}
export async function handler(request: Request): Promise<Response> { const { name } = request;
return { message: "Hello " + name };}You can also define a more flexible handler like this:
export async function handler(request: Request): Promise<any> {}State Management
Section titled “State Management”The functions maintain state as long as the instance is warm.
This means that any variables defined outside the handler function will persist across multiple invocations, allowing you to store data in memory between calls.
However, keep in mind that function instances can be terminated at any time due to scaling events or inactivity. Therefore, it’s important not to rely on in-memory state for critical data that needs to persist longer term.
Logging
Section titled “Logging”You can use standard logging methods such as console.log, console.error, and console.warn within your function code.
These logs will be captured and can be viewed in the Infragate Console under the “Monitoring” section for your MCP server.