Skip to content

Instantly share code, notes, and snippets.

@dacr
Created December 15, 2025 17:29
Show Gist options
  • Select an option

  • Save dacr/16c96022ed075230fd5c7571c85446f8 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/16c96022ed075230fd5c7571c85446f8 to your computer and use it in GitHub Desktop.
hello mcp server / published by https://github.com/dacr/code-examples-manager #dccd5b3c-b53d-4c0b-8f91-b9889c3203f7/a993f011a8447a5f4162fd1cd13cf6b3db9f42c
// summary : hello mcp server
// keywords : artificial-intelligence, generative-ai, llm, ai, mcp, mcp-server, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : dccd5b3c-b53d-4c0b-8f91-b9889c3203f7
// created-on : 2025-07-01T14:23:09+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
//> using scala 3.7.1
//> using dep org.slf4j:slf4j-api:2.0.17
//> using dep org.slf4j:slf4j-simple:2.0.17
//> using dep com.tjclp::fast-mcp-scala:0.1.1
//> using dep fr.janalyse::lorem-ipsum:1.0.7
//> using options "-Xcheck-macros" "-experimental"
/*
{
"mcpServers": {
"hello-fast-mcp-server": {
"command": "scala-cli",
"args": [
"hello-mcp-server.sc",
"--offline",
"--quiet"
]
}
}
}
*/
/*
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion": "2024-11-05"}}
{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}
{"jsonrpc":"2.0","id":2,"method":"resources/list","params":{}}
{"jsonrpc":"2.0","id":3,"method":"prompts/list","params":{}}
{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"add","arguments":{"a":40,"b": 2}}}
{"jsonrpc":"2.0","id":5,"method":"prompts/greet","params":{"Name to greet":"joe"}}
{"jsonrpc":"2.0","id":6,"method":"prompts/loremipsum","params":{}}
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion": "2024-11-05"}}
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"hello"}}
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion": "2024-11-05"}}
{"jsonrpc":"2.0","id":1,"method":"prompts/get","params":{"name":"loremipsum"}}
*/
import com.tjclp.fastmcp.core.*
import com.tjclp.fastmcp.macros.RegistrationMacro.*
import com.tjclp.fastmcp.server.{FastMcpServer, FastMcpServerSettings}
import zio.*
// Define annotated tools, prompts, and resources
object Dummy {
// -------------------------------------------------------------------------
// TOOLS
// Tools are executable functions that perform specific actions or computations. They are designed to be called by clients to execute operations.
// Use cases: Mathematical calculations, data processing, API calls, file operations, system commands.
@Tool(name = Some("add"), description = Some("Add two numbers"))
def add(
@ToolParam("First operand") a: Double,
@ToolParam("Second operand") b: Double
): Double = a + b
@Tool(name = Some("multiply"), description = Some("Multiply two numbers"))
def multiply(
@ToolParam("First operand") a: Double,
@ToolParam("Second operand") b: Double
): Double = a * b
@Tool(name = Some("hello"), description = Some("Say hello"))
def hello(): String = "Hello, world!"
@Tool(name = Some("loremipsum"), description = Some("Generate a lorem-ipsum message"))
def generateLoremIpsum(): String = {
loremipsum.LoremIpsum.generate(42 * 6).map(_.text()).mkString("\n\n")
}
// -------------------------------------------------------------------------
// PROMPTS
// Prompts are template generators that create structured text or instructions, typically for use with language models.
// Use cases: Message templates, instruction generation, context formatting, prompt engineering.
@Prompt(name = Some("greet"), description = Some("Generate a greeting message"))
def greet(@PromptParam("Name to greet") name: String): String = {
s"Hello, $name!"
}
@Prompt(name = Some("farewell"), description = Some("Generate a farewell message"))
def farewell(@PromptParam("Name to say goodbye to") name: String): String = {
s"Goodbye, $name! Thank you for using our MCP server."
}
// -------------------------------------------------------------------------
// RESOURCES
// Resources represent data sources or content that can be accessed by clients. They provide read-only access to information.
// Examples: Files, databases, APIs, configuration data, documentation, logs.
}
object ExampleServer extends ZIOAppDefault {
override def run = {
val settings = FastMcpServerSettings(
debug = true,
logLevel = "DEBUG"
)
for {
server <- ZIO.succeed(FastMcpServer(name = "dummy-mcp-server", settings = settings))
_ <- ZIO.attempt(server.scanAnnotations[Dummy.type])
// _ <- ZIO.log("Starting stdio server...")
_ <- server
.runStdio()
.tapError(error => ZIO.log(s"Error running stdio: $error"))
.onInterrupt(ZIO.log("Server interrupted"))
} yield ()
}
}
ExampleServer.main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment