Skip to content

Commit 5aa23ac

Browse files
committed
move annoation to a separate module
1 parent 07977b5 commit 5aa23ac

File tree

7 files changed

+180
-133
lines changed

7 files changed

+180
-133
lines changed

feature.annotation/build.gradle.kts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import org.gradle.jvm.toolchain.JavaLanguageVersion
2+
3+
plugins {
4+
kotlin("jvm")
5+
kotlin("plugin.serialization")
6+
}
7+
group = "io.modelcontextprotocol.feature.annotation"
8+
version = "0.5.0"
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
15+
dependencies {
16+
implementation(project(":"))
17+
implementation(libs.kotlin.reflect)
18+
api(libs.kotlinx.serialization.json)
19+
testImplementation(libs.kotlin.test)
20+
testImplementation(libs.kotlinx.coroutines.test)
21+
}
22+
23+
tasks.test {
24+
useJUnitPlatform()
25+
}

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/annotations.kt renamed to feature.annotation/src/main/kotlin/io/modelcontextprotocol/annotation/Annotations.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
package io.modelcontextprotocol.kotlin.sdk.server
2-
3-
import kotlinx.serialization.json.JsonObject
4-
import kotlinx.serialization.json.buildJsonObject
5-
import kotlinx.serialization.json.put
6-
import kotlinx.serialization.json.putJsonObject
7-
import kotlin.reflect.KClass
1+
package io.modelcontextprotocol.annotation
82

93
/**
104
* Annotation to define an MCP tool with simplified syntax.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.modelcontextprotocol.annotation;
2+
3+
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
4+
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
5+
public class Main {
6+
public static void main(String[] args) {
7+
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
8+
// to see how IntelliJ IDEA suggests fixing it.
9+
System.out.printf("Hello and welcome!");
10+
11+
for (int i = 1; i <= 5; i++) {
12+
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
13+
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
14+
System.out.println("i = " + i);
15+
}
16+
}
17+
}

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerAnnotations.kt renamed to feature.annotation/src/main/kotlin/io/modelcontextprotocol/annotation/ServerAnnotations.kt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
1-
package io.modelcontextprotocol.kotlin.sdk.server
1+
package io.modelcontextprotocol.annotation
22

3-
import io.ktor.util.rootCause
4-
import io.modelcontextprotocol.kotlin.sdk.CallToolRequest
53
import io.modelcontextprotocol.kotlin.sdk.CallToolResult
64
import io.modelcontextprotocol.kotlin.sdk.TextContent
75
import io.modelcontextprotocol.kotlin.sdk.Tool
8-
import kotlinx.serialization.json.JsonObject
6+
import io.modelcontextprotocol.kotlin.sdk.server.Server
97
import kotlinx.serialization.json.JsonPrimitive
108
import kotlinx.serialization.json.buildJsonObject
119
import kotlinx.serialization.json.put
1210
import kotlinx.serialization.json.putJsonObject
1311
import java.lang.reflect.InvocationTargetException
14-
import kotlin.reflect.KCallable
15-
import kotlin.reflect.KClass
1612
import kotlin.reflect.KFunction
1713
import kotlin.reflect.KParameter
1814
import kotlin.reflect.KType
1915
import kotlin.reflect.full.findAnnotation
2016
import kotlin.reflect.full.hasAnnotation
2117
import kotlin.reflect.full.instanceParameter
2218
import kotlin.reflect.full.valueParameters
23-
import kotlin.reflect.typeOf
24-
import kotlin.text.get
25-
import kotlin.text.set
2619

2720
/**
28-
* Extension function to register tools from class methods annotated with [McpTool].
29-
* This function will scan the provided class for methods annotated with [McpTool] and register them as tools.
21+
* Extension function to register tools from class methods annotated with [io.modelcontextprotocooool.McpTool].
22+
* This function will scan the provided class for methods annotated with [io.modelcontextprotocooool.McpTool] and register them as tools.
3023
*
3124
* @param instance The instance of the class containing the annotated methods.
3225
* @param T The type of the class.
@@ -50,7 +43,7 @@ public inline fun <reified T : Any> Server.registerAnnotatedTools(instance: T) {
5043
*
5144
* @param instance The instance of the class containing the annotated method.
5245
* @param function The function to register as a tool.
53-
* @param annotation The [McpTool] annotation.
46+
* @param annotation The [io.modelcontextprotocooool.McpTool] annotation.
5447
*/
5548
public fun <T : Any> Server.registerToolFromAnnotatedFunction(
5649
instance: T,

0 commit comments

Comments
 (0)