class_study
服务介绍
Multi-Purpose MCP Server
Model Context Protocol (MCP) . , , , , .
- ** **:
- ** **: Asia/Seoul, America/New_York, Europe/London IANA
- ****:
- ** **:
- ** **:
- ** **: AI
time-mcp-server/
src/
index.ts # MCP
build/ # JavaScript ( )
package.json #
tsconfig.json # TypeScript
README.md #
1.
npm install
2.
Hugging Face API .
Hugging Face API
Windows (PowerShell):
$env:HF_TOKEN="your_hugging_face_token_here"
Windows (Command Prompt):
set HF_TOKEN=your_hugging_face_token_here
Linux/macOS:
export HF_TOKEN="your_hugging_face_token_here"
.env :
HF_TOKEN=your_hugging_face_token_here
3.
npm run build
4.
node build/index.js
build/ JavaScript , MCP .
1.
:
- ** **:
current_time - ****:
timezone(): (: Asia/Seoul, America/New_York, Europe/London)-
(Asia/Seoul)
2.
:
- ** **:
calculator - ****:
num1:num2:operation: (add, subtract, multiply, divide)
3.
:
- ** **:
greeting - ****:
name:language: (korean, english, japanese, chinese, spanish, french, german, italian, portuguese, russian)
4.
:
- ** **:
code_review - ****:
code:language(): (javascript, typescript, python, java, cpp, go, rust)reviewType(): (comprehensive, security, performance, readability, best_practices)
5.
AI :
- ** **:
generate_image - ****:
prompt:
- ** **: base64-encoded PNG
-
** ** ():
-
** **:
Europe/London -
** **:
5 3 ? 10 2? -
** **:
Hello -
** **:
: function add(a, b) { return a + b; } -
** **:
Asia/Seoul- ()America/New_York-America/Los_Angeles-Europe/London-Europe/Paris-Asia/Tokyo-Asia/Shanghai-Australia/Sydney-
****: IANA . IANA Time Zone Database .
MCP (Tool)
MCP server.tool() **Zod ** :
import { z } from 'zod'
//
server.tool(
'calculator',
{
operation: z
.enum(['add', 'subtract', 'multiply', 'divide'])
.describe(' (add, subtract, multiply, divide)'),
a: z.number().describe(' '),
b: z.number().describe(' ')
},
async ({ operation, a, b }) => {
//
let result: number
switch (operation) {
case 'add':
result = a + b
break
case 'subtract':
result = a - b
break
case 'multiply':
result = a * b
break
case 'divide':
if (b === 0) throw new Error('0 ')
result = a / b
break
default:
throw new Error(' ')
}
const operationSymbols = {
add: '+',
subtract: '-',
multiply: '',
divide: ''
} as const
const operationSymbol =
operationSymbols[operation as keyof typeof operationSymbols]
return {
content: [
{
type: 'text',
text: `${a} ${operationSymbol} ${b} = ${result}`
}
]
}
}
)
//
server.tool(
'get_weather',
{
city: z.string().describe(' '),
unit: z
.enum(['celsius', 'fahrenheit'])
.optional()
.default('celsius')
.describe(' (: celsius)')
},
async ({ city, unit }) => {
try {
// API ()
const weatherData = await fetchWeatherData(city, unit)
return {
content: [
{
type: 'text',
text: `${city} :
: ${weatherData.temperature}${unit === 'celsius' ? 'C' : 'F'}
: ${weatherData.condition}
: ${weatherData.humidity}%
: ${weatherData.windSpeed}km/h`
}
]
}
} catch (error) {
throw new Error(
` : ${(error as Error).message}`
)
}
}
)
//
async function fetchWeatherData(city: string, unit: string) {
// API
//
return {
temperature: unit === 'celsius' ? 22 : 72,
condition: '',
humidity: 65,
windSpeed: 12
}
}
MCP :
//
server.resource(
'example-file',
'file://example.txt',
{
name: ' ',
description: ' ',
mimeType: 'text/plain'
},
async () => {
return {
contents: [
{
uri: 'file://example.txt',
mimeType: 'text/plain',
text: ' .'
}
]
}
}
)
//
server.resource(
'app-settings',
'config://settings',
{
name: ' ',
description: ' ',
mimeType: 'application/json'
},
async () => {
const settings = {
theme: 'dark',
language: 'ko-KR',
notifications: true,
lastUpdated: new Date().toISOString()
}
return {
contents: [
{
uri: 'config://settings',
mimeType: 'application/json',
text: JSON.stringify(settings, null, 2)
}
]
}
}
)
- @modelcontextprotocol/sdk: MCP SDK
- @huggingface/inference: Hugging Face Inference API ( )
- zod: TypeScript
- typescript: TypeScript
npm run build: TypeScript JavaScript
// ()
const koreanTime = await getCurrentTime() // "2024-01-15 14:30:25 (Asia/Seoul)"
//
const newYorkTime = await getCurrentTime('America/New_York') // "2024-01-15 00:30:25 (America/New_York)"
//
const londonTime = await getCurrentTime('Europe/London') // "2024-01-15 05:30:25 (Europe/London)"
import { Server } from '@modelcontextprotocol/sdk/server/index.js'
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js'
import { z } from 'zod'
//
const TimeToolSchema = z.object({
timezone: z.string().optional().describe(' (: Asia/Seoul, America/New_York)')
})
//
const getCurrentTime = (timezone: string = 'Asia/Seoul'): string => {
const now = new Date()
const options: Intl.DateTimeFormatOptions = {
timeZone: timezone,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
}
const formatter = new Intl.DateTimeFormat('ko-KR', options)
const timeString = formatter.format(now)
return `${timeString} (${timezone})`
}
//
const server = new Server(
{
name: 'time-mcp-server',
version: '1.0.0',
},
{
capabilities: {
tools: {},
},
}
)
//
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: 'current_time',
description: ' ',
inputSchema: {
type: 'object',
properties: {
timezone: {
type: 'string',
description: ' (: Asia/Seoul, America/New_York)'
}
},
required: []
}
}
]
}
})
//
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === 'current_time') {
const { timezone } = TimeToolSchema.parse(request.params.arguments)
const currentTime = getCurrentTime(timezone)
return {
content: [
{
type: 'text',
text: ` : ${currentTime}`
}
]
}
}
throw new Error(` : ${request.params.name}`)
})
//
async function main() {
const transport = new StdioServerTransport()
await server.connect(transport)
console.error('Time MCP Server started')
}
main().catch(console.error)
Cursor MCP
MCP Cursor :
./.cursor/mcp.json :
{
"mcpServers": {
"typescript-mcp-server": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/YOUR/PROJECT/build/index.js"]
}
}
}
****: .
pwd.
Cursor MCP :
- " " ( )
- " " ( )
- "Europe/London " ( )
- "5 3 ?" ( )
- " " ( )
- " : function add(a, b) { return a + b; }" ( )
- " " ( )
MIT