Skip to content

Commit ef1cef7

Browse files
committed
feat: auto-generated changes
1 parent 38930e9 commit ef1cef7

File tree

2 files changed

+11
-164
lines changed

2 files changed

+11
-164
lines changed

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@
88
"ai",
99
"assistant"
1010
],
11-
"main": "./build/main.js",
12-
"types": "./build/main.d.ts",
11+
"main": "./build/index.js",
12+
"types": "./build/index.d.ts",
1313
"type": "module",
1414
"files": [
1515
"build/",
1616
"README.md",
1717
"LICENSE"
1818
],
19+
"bin": {
20+
"habitify-mcp-server": "./build/index.js"
21+
},
1922
"scripts": {
2023
"test": "jest --passWithNoTests --coverage",
21-
"dev": "tsx watch ./src/main.ts",
24+
"dev": "tsx watch ./src/index.ts",
2225
"build": "tsc -p tsconfig.json",
2326
"lint": "eslint ./src --ext .ts",
2427
"format": "prettier --write .",
@@ -27,7 +30,7 @@
2730
"commitlint": "commitlint --edit",
2831
"typecheck": "tsc --noEmit",
2932
"audit": "npm audit --omit=dev",
30-
"inspect": "npx @modelcontextprotocol/inspector node ./build/main.js"
33+
"inspect": "npx @modelcontextprotocol/inspector node ./build/index.js"
3134
},
3235
"engines": {
3336
"node": ">=18.0.0"

src/index.ts

Lines changed: 4 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
55
import { z } from 'zod'
66
import axios, { AxiosInstance } from 'axios'
77
import dotenv from 'dotenv'
8-
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'
98

109
dotenv.config()
1110

1211
const envSchema = z.object({
13-
HABITIFY_API_KEY: z.string().min(1),
12+
HABITIFY_API_KEY: z.string(),
1413
})
1514

1615
const env = envSchema.parse(process.env)
@@ -21,11 +20,11 @@ const mcpServer = new McpServer(
2120
version: '',
2221
},
2322
{
23+
instructions: `API for Habitify habit tracking service`,
2424
capabilities: {
2525
tools: {},
2626
logging: {},
2727
},
28-
instructions: `MCP server for Habitify API integration - track habits, manage mood logs, and automate habit tracking workflows directly from AI assistants like Claude and Cursor`,
2928
}
3029
)
3130

@@ -39,7 +38,7 @@ const logger = {
3938
}
4039

4140
const apiClient: AxiosInstance = axios.create({
42-
baseURL: 'https://api.habitify.me',
41+
baseURL: '',
4342
headers: {
4443
Accept: 'application/json',
4544
},
@@ -59,165 +58,10 @@ apiClient.interceptors.request.use(
5958
}
6059
)
6160

62-
function handleResult(data: unknown): CallToolResult {
63-
return {
64-
content: [
65-
{
66-
type: 'text',
67-
text: JSON.stringify(data, null, 2),
68-
},
69-
],
70-
}
71-
}
72-
73-
function handleError(error: unknown): CallToolResult {
74-
console.error(error)
75-
logger.error('Error occurred:', JSON.stringify(error))
76-
77-
if (axios.isAxiosError(error)) {
78-
const message = error.response?.data?.description || error.message
79-
return {
80-
isError: true,
81-
content: [{ type: 'text', text: `API Error: ${message}` }],
82-
} as CallToolResult
83-
}
84-
85-
return {
86-
isError: true,
87-
content: [{ type: 'text', text: `Error: ${error}` }],
88-
} as CallToolResult
89-
}
90-
91-
mcpServer.tool('get-journal', `Get habit journal for a specific date`, {}, async (args) => {
92-
try {
93-
const response = await apiClient.get('/journal', {
94-
params: args,
95-
})
96-
return handleResult(response.data)
97-
} catch (error) {
98-
return handleError(error)
99-
}
100-
})
101-
102-
mcpServer.tool('post-logs-by-id', `Add a habit log`, {}, async (args) => {
103-
try {
104-
const response = await apiClient.post('/logs/{habit_id}', args)
105-
return handleResult(response.data)
106-
} catch (error) {
107-
return handleError(error)
108-
}
109-
})
110-
111-
mcpServer.tool('delete-logs-by-id', `Delete habit logs in date range`, {}, async (args) => {
112-
try {
113-
const response = await apiClient.delete('/logs/{habit_id}', {
114-
params: args,
115-
})
116-
return handleResult(response.data)
117-
} catch (error) {
118-
return handleError(error)
119-
}
120-
})
121-
122-
mcpServer.tool('delete-logs-by-id-by-id', `Delete a specific habit log`, {}, async (args) => {
123-
try {
124-
const response = await apiClient.delete('/logs/{habit_id}/{log_id}', {
125-
params: args,
126-
})
127-
return handleResult(response.data)
128-
} catch (error) {
129-
return handleError(error)
130-
}
131-
})
132-
133-
mcpServer.tool('get-habits', `Get all habits`, {}, async (args) => {
134-
try {
135-
const response = await apiClient.get('/habits', {
136-
params: args,
137-
})
138-
return handleResult(response.data)
139-
} catch (error) {
140-
return handleError(error)
141-
}
142-
})
143-
144-
mcpServer.tool('get-habits-by-id', `Get habit details`, {}, async (args) => {
145-
try {
146-
const response = await apiClient.get('/habits/{habit_id}', {
147-
params: args,
148-
})
149-
return handleResult(response.data)
150-
} catch (error) {
151-
return handleError(error)
152-
}
153-
})
154-
155-
mcpServer.tool('get-areas', `Get all areas`, {}, async (args) => {
156-
try {
157-
const response = await apiClient.get('/areas', {
158-
params: args,
159-
})
160-
return handleResult(response.data)
161-
} catch (error) {
162-
return handleError(error)
163-
}
164-
})
165-
166-
mcpServer.tool('get-moods', `Get mood entries`, {}, async (args) => {
167-
try {
168-
const response = await apiClient.get('/moods', {
169-
params: args,
170-
})
171-
return handleResult(response.data)
172-
} catch (error) {
173-
return handleError(error)
174-
}
175-
})
176-
177-
mcpServer.tool('post-moods', `Add mood entry`, {}, async (args) => {
178-
try {
179-
const response = await apiClient.post('/moods', args)
180-
return handleResult(response.data)
181-
} catch (error) {
182-
return handleError(error)
183-
}
184-
})
185-
186-
mcpServer.tool('get-notes', `Get notes`, {}, async (args) => {
187-
try {
188-
const response = await apiClient.get('/notes', {
189-
params: args,
190-
})
191-
return handleResult(response.data)
192-
} catch (error) {
193-
return handleError(error)
194-
}
195-
})
196-
197-
mcpServer.tool('post-notes', `Add note`, {}, async (args) => {
198-
try {
199-
const response = await apiClient.post('/notes', args)
200-
return handleResult(response.data)
201-
} catch (error) {
202-
return handleError(error)
203-
}
204-
})
205-
206-
mcpServer.tool('get-actions', `Get available actions`, {}, async (args) => {
207-
try {
208-
const response = await apiClient.get('/actions', {
209-
params: args,
210-
})
211-
return handleResult(response.data)
212-
} catch (error) {
213-
return handleError(error)
214-
}
215-
})
216-
21761
async function main() {
21862
const transport = new StdioServerTransport()
21963
await mcpServer.server.connect(transport)
220-
logger.log('Habitify MCP Server started')
64+
logger.log('Habitify API MCP Server started')
22165
}
22266

22367
main().catch((error) => {

0 commit comments

Comments
 (0)